如何ReSize图像与良好的质量在iPhone [英] How to ReSize Image with Good Quality in iPhone
问题描述
我想在iPhone中创建一个照片库作为现有照片库。我在从照片库中选择的scrollviewer中添加图像。添加图像之前调整所选图像的大小,并将其设置为ImageView控制。但当我比较添加的图像质量与iPhone照片库图像质量,我的控制图像不好。如何带来质量和withou内存溢出问题。
I want to create a Photos Library as existing photo library in iPhone. I add image in scrollviewer which is chosen from Photo library. Before add image i resize the selected image and set it to ImageView Control.But when i compare to added image quality with iPhone Photo library image quality, my control image is not good. How to bring the quality and withou memory overflow issue.
-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
// Create a bitmap context.
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
推荐答案
进入这个问题。我想你使用的是带有Retina显示屏的iPhone 4。即使你不是,你应该解释它。取代 UIGraphicsBeginImageContext()
,请使用 UIGraphicsBeginImageContextWithOptions()
并使用 scale
属性 UIScreen
用于第三个参数。所有iOS设备都有scale属性,在iPhone 4上设置为2.0;
I ran into this issue also. I think you're using an iPhone 4 with Retina Display. Even if you're not, you should account for it. Instead of UIGraphicsBeginImageContext()
, use UIGraphicsBeginImageContextWithOptions()
and use the scale
property of UIScreen
for the third argument. All iOS devices have the scale property, on iPhone 4 it's set to 2.0; on the rest, as I write this, it's set to 1.0.
因此,你的代码,与这些变化,变成
So your code, with those changes, becomes
-(UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
// Create a bitmap context.
UIGraphicsBeginImageContextWithOptions(newSize, YES, [UIScreen mainScreen].scale);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
这篇关于如何ReSize图像与良好的质量在iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!