如何在iPhone objective-c中降低图像质量/尺寸? [英] How do I reduce Image quality/size in iPhone objective-c?

查看:178
本文介绍了如何在iPhone objective-c中降低图像质量/尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,让用户可以用他/她的iPhone拍照并将其用作应用程序的背景图像。我使用 UIImagePickerController 让用户拍照并将背景 UIImageView 图像设置为返回的 UIImage object。

I have an app that lets the user take a picture with his/her iPhone and use it as a background image for the app. I use UIImagePickerController to let the user take a picture and set the background UIImageView image to the returned UIImage object.

IBOutlet UIImageView *backgroundView;

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
 backgroundView.image = image;
 [self dismissModalViewControllerAnimated:YES];
}

一切正常。
如何将 UIImage 的大小减小到480x320,这样我的应用程序才能提高内存效率?
我不在乎我是否放弃任何图像质量。

This all works fine. How can I reduce the size of the UIImage to 480x320 so my app can be memory efficient? I don't care if I loose any image quality.

提前致谢。

推荐答案

您可以创建图形上下文,将图像绘制成所需比例的图像,然后使用返回的图像。例如:

You can create a graphics context, draw the image into that at the desired scale, and use the returned image. For example:

UIGraphicsBeginImageContext(CGSizeMake(480,320));

CGContextRef            context = UIGraphicsGetCurrentContext();

[image drawInRect: CGRectMake(0, 0, 480, 320)];

UIImage        *smallImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();    

这篇关于如何在iPhone objective-c中降低图像质量/尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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