How do you crop an image in iOS(如何在 iOS 中裁剪图像)
问题描述
我有一个照片应用程序,您可以在其中在一个部分中添加贴纸.完成后,我想保存图像.这是我必须这样做的代码.
I have a photo app where you can add stickers in one section. When you're finished I want to save the image. Here is the code that I have to do that.
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/照片%202012-04-09%201%2036%2018%20PM.png
Now the image that gets saved is the full screen of the image, which is fine, but now I need to crop the image and I don't know how. You can see the image at the link below: http://dl.dropbox.com/u/19130454/Photo%202012-04-09%201%2036%2018%20PM.png
我需要裁剪:左右91px距离底部 220 像素
I need to crop: 91px from the left and right 220px from the bottom
任何帮助将不胜感激.如果我没有解释清楚,请告诉我,我会尽力重新解释.
Any help would be greatly appreciated. If I haven't explained things clearly, please let me know and I'll do my best to re-explain.
推荐答案
这样的怎么样
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);
这篇关于如何在 iOS 中裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 中裁剪图像
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01