tags:

views:

144

answers:

1

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.

+1  A: 

Why are you releasing maskRef? You shouldn't because yo didn't retained it.

tt.Kilew