5

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?

Olivier
  • 839
  • 11
  • 17
ayon
  • 2,160
  • 2
  • 17
  • 31

4 Answers4

3

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.

GuybrushThreepwood
  • 5,549
  • 9
  • 53
  • 111
2

JPGs don't have transparency so as soon as you convert it to JPG alpha is gone. This is a known limitation of UIImageWriteToSavedPhotosAlbum

it doesn't keep png.

Daij-Djan
  • 48,496
  • 17
  • 105
  • 132
1

try this. this code working for me

  UIGraphicsBeginImageContext(baseViewOne.frame.size);
            [[baseViewOne layer] renderInContext:UIGraphicsGetCurrentContext()];
            UIImage * screenshota = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();

also check cocoa coder screen shots

Muruganandham K
  • 5,175
  • 5
  • 31
  • 60
0
NSData* imdata = UIImagePNGRepresentation(_snapshotImgView.image);
UIImage* snapshotPNG = [UIImage imageWithData:imdata];

UIImageWriteToSavedPhotosAlbum(snapshotPNG, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
inf3rno
  • 22,333
  • 10
  • 106
  • 183
Saro Bear
  • 9
  • 1