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
  • 858
  • 8
  • 17
ayon
  • 2,180
  • 2
  • 17
  • 32

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,598
  • 9
  • 55
  • 113
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
  • 49,552
  • 17
  • 113
  • 135
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,271
  • 5
  • 34
  • 62
0
NSData* imdata = UIImagePNGRepresentation(_snapshotImgView.image);
UIImage* snapshotPNG = [UIImage imageWithData:imdata];

UIImageWriteToSavedPhotosAlbum(snapshotPNG, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
inf3rno
  • 24,976
  • 11
  • 115
  • 197
Saro Bear
  • 9
  • 1