gpt4 book ai didi

iphone - 你如何在 iOS 中裁剪图像

转载 作者:IT王子 更新时间:2023-10-29 07:54:02 25 4
gpt4 key购买 nike

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

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

我需要裁剪:从左到右91px距底部 220px

如有任何帮助,我们将不胜感激。如果我没有解释清楚,请告诉我,我会尽力重新解释。

最佳答案

这样的事情怎么样

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);

关于iphone - 你如何在 iOS 中裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10079701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com