I added an overlay to my image (selected from photo album) and I can't save the composite, the following code only saves the original image. Any one out have a suggestion to modify the image object to have the added image?
#pragma mark -
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
overlay.alpha = 0.6; // Customize the opacity of the top image.
[imageView addSubview:overlay];
CGContextRef context = U开发者_如何学PythonIGraphicsGetCurrentContext();
//UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save image
UIImageWriteToSavedPhotosAlbum(imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), context);
[picker dismissModalViewControllerAnimated:YES];
}
UIImageWriteToSavedPhotosAlbum(imageView.image.layer, self)
Thank you @Rahul Vyas. I didn't try your suggestion, but I still appreciate your input. Ended up getting this issue resolved from help from the Apple Dev forums.
The answer to this problem is, as it worked for me:
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(context, screenRect);
[imageView.layer renderInContext:context];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save image
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), context);
[picker dismissModalViewControllerAnimated:YES];
精彩评论