如何降低 iPhone Objective-c 中的图像质量/尺寸?
我有一个应用程序,可以让用户用他/她的 iPhone 拍照并将其用作应用程序的背景图像。我使用 UIImagePickerController 让用户拍照并将背景 UIImageView 图像设置为返回的 UIImage 对象。
IBOutlet UIImageView *backgroundView;
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
backgroundView.image = image;
[self dismissModalViewControllerAnimated:YES];
}
这一切都很好。 如何将 UIImage
的大小减小到 480x320,以便我的应用程序可以提高内存效率? 我不在乎是否会失去任何图像质量。
提前致谢。
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];
}
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.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建图形上下文,以所需的比例将图像绘制到其中,然后使用返回的图像。例如:
You can create a graphics context, draw the image into that at the desired scale, and use the returned image. For example:
我知道这个问题已经解决了,但是如果有人(像我一样)想要缩放图像并保持纵横比,则以下代码可能会有所帮助:
I know this question is already solved, but just if someone (like i did) wants to scale the image keeping the aspect ratio, this code might be helpful:
使用 contentOfFile 并确保所有图像都是 .png。 Apple 针对 png 进行了优化。
哦,使用 contentOfFile 而不是 imageName 方法。有几个原因。即使在调用 [release] 后,由 ImageName 引入内存的图像仍保留在内存中。
别问我为什么。苹果是这么告诉我的。
罗伊德尔·克拉克
Use contentOfFile and make sure that all of your images are .png. Apple is optimized for png.
Oh, use the contentOfFile not the imageName method. Several reasons for that. Images that is brought in memory by ImageName remained in memory even after a [release] is called.
Dont ask my why. The apple told me so.
Roydell Clarke