简体   繁体   English

iOS UIImage节省质量损失?

[英]iOS UIImage Saving Loss of Quality?

I seem to be losing quality when saving an UIImage to the Photo Library. 将UIImage保存到照片库时,我似乎正在失去质量。 Any ideas how to fix it? 任何想法如何解决? Here is the important code: 这是重要的代码:

-(IBAction)aExportPhoto:(id)sender
{
UIImage *main = [self imageWithView:imageFrame];
UIImage *water = [self imageWithView:waterFrame];
UIImage *lign = [self imageWithView:lignFrame];

CGRect fMain = imageFrame.frame;
CGRect fWater = waterFrame.frame;
CGRect fLign = lignFrame.frame;

CGSize sMain = fMain.size;
CGSize sWater = fWater.size;
CGSize sLign = fLign.size;

UIGraphicsBeginImageContext(sMain);

[main drawInRect:CGRectMake(0, 0, sMain.width, sMain.height)];
[lign drawInRect:CGRectMake(fMain.origin.x, sMain.height - 25, sMain.width - 45, 20) blendMode:kCGBlendModeNormal alpha:1.0f];
[water drawInRect:CGRectMake(sMain.width - 45, sMain.height - 35, 40, 40) blendMode: kCGBlendModeNormal alpha: 1.0f];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
UIGraphicsEndImageContext();

}

Here is the imageWithView method: 这是imageWithView方法:

- (UIImage *) imageWithView:(UIImageView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return img;
}

Thanks in advance! 提前致谢!

You should use UIGraphicsBeginImageContextWithOptions in aExportPhoto , like you did in imageWithView . 您应该在aExportPhoto使用UIGraphicsBeginImageContextWithOptions ,就像在imageWithView UIGraphicsBeginImageContext uses a scale of 1 (non-retina resolution), and you want to use 0 (the scale of the device). UIGraphicsBeginImageContext使用1 (非视网膜分辨率)的比例,而您想使用0 (设备的比例)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM