iOS always add white background to images - ios

I am writing an app process image. But when I change alpha of an image to 0, it mean that this image will be transparent. And then I save this image to photo library.
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
But when I open this image again, i see that it has white background.
Does anybody know why?

Did you saved as jpeg?
try this:
NSData* pngdata = UIImagePNGRepresentation (image);
UIImage* img = [UIImage imageWithData:pngdata];
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);

Related

Implicit declaration of function 'UIImageWriteToSavedPhotosAlbum' is invalid in C99

I want save image to camera roll in apple Watch
this is my code:
UIImage *image = [UIImage imageNamed:#"w0-1.jpg"];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
can you help me please??
You cannot save image to saved photo album. You can only save image to your application folder.

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?
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.
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.
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
NSData* imdata = UIImagePNGRepresentation(_snapshotImgView.image);
UIImage* snapshotPNG = [UIImage imageWithData:imdata];
UIImageWriteToSavedPhotosAlbum(snapshotPNG, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);

Save image with my own custom image in ios

I want to save an image to camera roll with my own imagename in ios 5.I am using AV Foundation for accessing camera features.Please help me with possible solutions.
// Image to save
UIImage *img = [UIImage imageNamed:#"ImageName.png"];
// Request to save the image to camera roll
UIImageWriteToSavedPhotosAlbum(img, self,
#selector(image:didFinishSavingWithError:contextInfo:), nil);
Hope this helps..

UIImageWriteToSavedPhotosAlbum - Failed to encode image for saved photos

In my main ViewController, I generate an image from UIGraphicsGetImageFromCurrentImageContext(). The image is assigned to a UIImage, and I've tested it by placing in a UIImageView in the main view, so I can see it. Works just fine. However when I tap a button I've assigned to save it, I get the error: -3304 "Failed to encode image for saved photos."
screenshot code:
CGSize mySize = CGSizeMake(530, 350);
UIGraphicsBeginImageContext(mySize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -444, -313);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
// self.screenshot is a UIImage declared in .h
self.screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Save code:
UIImageWriteToSavedPhotosAlbum(screenshot, self, #selector(imageWasSavedSuccessfully:didSaveWithError:contextInfo:), NULL);
Not sure if I'm not meeting the requirements for camera roll images, or if that method can only be used in conjunction with the UIPickerController class. Thanks for your help.
For posterity, the issue was that the image to be saved was nil.
Try to save your image like this:
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
or maybe
UIImageWriteToSavedPhotosAlbum(self.screenshot, nil, nil, nil);
or maybe even
UIImageWriteToSavedPhotosAlbum(screenshot, self, nil, nil);

Can you save PNG's to the photo library in iOS5?

I've noticed that line drawings from the drawing app I'm making are very low quality when saved using this code:
UIImage *imageToSave = drawImage.image;
UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil);
As far as I can understand, you can't set the JPG quality when using UIImageWriteToSavedPhotosAlbum.
Is there a way to save the UIImage as a PNG to the photo library directly, or some way to increase the JPG quality? When doing a screenshot (pressing on/off+home on the iPad) the quality of the grabbed picture is perfect, but I can't expect people to save images that way.
Any help greatly appreciated!
Try this
NSData* pngdata = UIImagePNGRepresentation (drawImage.image); //PNG wrap
UIImage* img = [UIImage imageWithData:pngdata];
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);

Resources