如何在iOS中裁剪图像

flite3

我有一个照片应用程序,您可以在其中添加贴纸。完成后,我要保存图像。这是我要做的代码。

if(UIGraphicsBeginImageContextWithOptions != NULL)
{
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 2.5);
} else {
    UIGraphicsBeginImageContext(self.view.frame.size);
}
CGContextRef contextNew=UIGraphicsGetCurrentContext();

[self.view.layer renderInContext:contextNew];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

现在保存的图像是图像的全屏,这很好,但是现在我需要裁剪图像,我不知道如何。您可以在下面的链接中查看图像:http : //dl.dropbox.com/u/19130454/Photo%202012-04-09%201%2036%2018%20PM.png

我需要裁切:左侧为91像素,底部为220像素

任何帮助将不胜感激。如果我没有清楚地说明事情,请告诉我,我将尽力重新解释。

卢卡斯

这样的事情怎么样

CGRect clippedRect  = CGRectMake(self.view.frame.origin.x+91, self.view.frame.origin.y, self.view.frame.size.width-91*2, self.view.frame.size.height-220);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);
UIImage *newImage   = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章