可能重复:Saving two Overlapping UIImage
在UIScrollView中,我添加了我的UIImageView,它上面有一个 frame Layer 。我想在所有编辑后将最终图像保存在屏幕上。对上述问题给出的答案是有效的,但是当它绘制框架时,会导致<强烈的图像质量下降,所以我正在寻找一种能让我的图像保持良好分辨率的解决方案。 请提前帮助我,谢谢!
答案 0 :(得分:1)
尝试使用此代码:
//merge two images for this code
UIImage *bottomImage =imgview.image; //background image ////1st image
UIImage *image = imgProfile.image; //foreground image///2nd image
CGSize newSize = CGSizeMake(270, 330); // set your image rect
UIGraphicsBeginImageContext( newSize );
// Use existing opacity as is
[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];///1st image set frame
// Apply supplied opacity if applicable
[image drawInRect:CGRectMake(81,218,97,78) blendMode:kCGBlendModeNormal alpha:1]; //2nd image set frame on bottom image with alpha value
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
NSData *imageData = UIImagePNGRepresentation(newImage);
[imageData writeToFile:savedImagePath atomically:NO];
您可以在应用程序的文档目录中看到新创建的图像。