Crashing when masking an image

Posted by shameer on Stack Overflow See other posts from Stack Overflow or by shameer
Published on 2009-06-04T08:40:54Z Indexed on 2010/05/23 7:30 UTC
Read the original article Hit count: 293

Filed under:
|

I am trying to mask an image with a 'mask image". its work fine at first time. but when i try one more time with in the application with same mask image . Application crashed. but when trying with another mask image it works fine. Why this happens? pls help? Console shows ": CGImageMaskCreate: invalid mask bits/component: 4294967295."

  • (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

    CGImageRef maskRef = maskImage.CGImage;
    

    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false);

    CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); UIImage *img2=[UIImage imageWithCGImage:masked];

    CGImageRelease(maskRef);
    CGImageRelease(mask);
    CGImageRelease(masked);
    
    
    return img2;
    

}

fun1() { view.image=[self maskImage:image1 withMask:[UIImage imageNamed:@"image2.png"]]; }

fun2() { view.image=[self maskImage:image1 withMask:[UIImage imageNamed:@"image2.png"]]; view.image=[self maskImage:image1 withMask:[UIImage imageNamed:@"image3.png"]]; }

fun3() { view.image=[self maskImage:image1 withMask:[UIImage imageNamed:@"image2.png"]]; view.image=[self maskImage:image1 withMask:[UIImage imageNamed:@"image2.png"]]; }

When calling fun1 and fun2 apllication works fine. Application crashing when calling fun3.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about SDK