从UIImage返回子图像 [英] Return a subimage from a UIImage

查看:80
本文介绍了从UIImage返回子图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从UIImage中获取一个子图像。我四处寻找类似的问题,但无济于事。

I want to grab a subimage from a UIImage. I've looked around for a similar question, to no avail.

我知道我想要抓取的像素范围 - 如何从现有图像中返回此子图像?

I know the range of pixels I want to grab - how can I return this subimage, from an existing image?

推荐答案

这应该有所帮助: http://iphonedevelopment.blogspot.com/2010/11/drawing-part-of-uiimage.html

此代码段创建了一个 UIImage 的类别,但代码应该很容易修改,无需作为类别。

This code snippet is creating a category of UIImage but the code should be easily modified to work without it being a category.

执行相同操作的更简单方法如下:

A shorter way of doing the same thing is the following:

CGRect fromRect = CGRectMake(0, 0, 320, 480); // or whatever rectangle

CGImageRef drawImage = CGImageCreateWithImageInRect(image.CGImage, fromRect);
UIImage *newImage = [UIImage imageWithCGImage:drawImage];
CGImageRelease(drawImage);

希望这有帮助!

这篇关于从UIImage返回子图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆