iOS UIImage 保存质量下降?
iOS UIImage Saving Loss of Quality?
将 UIImage 保存到照片库时,我的质量似乎有所下降。任何想法如何解决它?这是重要的代码:
-(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();
}
这是 imageWithView 方法:
- (UIImage *) imageWithView:(UIImageView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
提前致谢!
您应该像在 imageWithView
中那样在 aExportPhoto
中使用 UIGraphicsBeginImageContextWithOptions
。 UIGraphicsBeginImageContext
使用 1
的比例(非视网膜分辨率),而您想使用 0
(设备的比例)。
将 UIImage 保存到照片库时,我的质量似乎有所下降。任何想法如何解决它?这是重要的代码:
-(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();
}
这是 imageWithView 方法:
- (UIImage *) imageWithView:(UIImageView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
提前致谢!
您应该像在 imageWithView
中那样在 aExportPhoto
中使用 UIGraphicsBeginImageContextWithOptions
。 UIGraphicsBeginImageContext
使用 1
的比例(非视网膜分辨率),而您想使用 0
(设备的比例)。