2

I am using UIImagePicker to load an image that I have upload to the photo library (on my iPad), however it loads without the alpha channel. I have tripple checked to make sure the image has one. Unless it is removed when syncing to itunes?

Here is the code I am using for the image picker when it finishes picking:

-(void)imagePickerController: (UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{   
    //dissmiss picker
    [imagePopOver dismissPopoverAnimated:YES];

    //get the picker image
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    //create image view for selected image
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height);
    imageView.center = CGPointMake(512, 384);
    [imageLayer addSubview:imageView];

    //release image and image view
    [image release];
    [imageView release];
}

What am I doing wrong? I hope this isn't a 'Doh!' moment.

Kangoo
  • 143
  • 3
  • 15

3 Answers3

6

UIImagePicker does support images with an alpha channel, as Kangoo states in their own answer.

However, the conditions for it working correctly are more complicated than just downloading an image through browser to photo lib.

First of all, it makes most sense to be using iOS's image picker to be picking only from the Camera Roll. On an iOS device, it's possible to save images from Mail or Safari to the Camera Roll, and other apps that support images with an alpha channel allow you to save to the Camera Roll.

Images in the rest of the Photos Library, other than the Camera Roll, would have gotten there by iTunes sync. And that's a problem. Although iPhoto on OSX does support PNG images with alpha channel, when iTunes sync pushes those images to an iOS device the transparent areas of the image background become opaque white.

Second, if you configure iOS's image picker to allow editing (square crop, move, scale), then the transparent areas of the image background will become opaque black!

But if you configure iOS's image picker to NOT allow editing, and you pick an image from the Camera Roll, then the picked image (UIImage) can have an alpha channel.

On the picked UIImage, use CGImageGetAlphaInfo(pickedImage.CGImage) to get the CGImageAlphaInfo, and if that info is not (kCGImageAlphaNone or kCGImageAlphaNoneSkipFirst or kCGImageAlphaNoneSkipLast) then the image has an alpha channel.

  • Welcome to stackoverflow. You could make this answer more useful by adding some references. – CCoder Nov 14 '12 at 05:26
0

Never mind. It was as I suspected. The alpha channel is lost somehow when importing the png through itunes (syncing). Must be converting to 24bit? I uploaded my image to the web and then downloaded it through browser to photo lib and it's fine now.

Kangoo
  • 143
  • 3
  • 15
-1

Have you tried calling:

imageView.backgroundColor = [UIColor clear]

Probably you may need to make sure that imageLayer is transparent, too. I am not sure how this has been implemented.

zoverf
  • 29
  • 2