Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep transparency in screenshot iOS

I am taking screenshot of a particular View in my Xib file with the following code...

UIView* captureView = self.view;
UIGraphicsBeginImageContextWithOptions(captureView.bounds.size, NO , 0.0f);
[captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

It works fine and saves JPG image to camera roll.

But problem is, There is another UIImageView on the top of my View, that UIImageView has a semi-transparent image in it. My screenshot doesn't preserve that transparency in the screenshot it is taking. I want to keep the transparency as it is in the actual screen.

How can you preserve the transparency in the screenshot?

like image 914
ayon Avatar asked Nov 30 '13 11:11

ayon


1 Answers

If you specify "No" for the opaque property, your image must include an alpha channel for this to work. Check that your image has an alpha channel.

like image 174
GuybrushThreepwood Avatar answered Nov 15 '22 05:11

GuybrushThreepwood