Image Masking Problem

Posted by Adnan Sohail on Stack Overflow See other posts from Stack Overflow or by Adnan Sohail
Published on 2010-05-31T11:21:22Z Indexed on 2010/05/31 11:22 UTC
Read the original article Hit count: 363

Filed under:

Hi I am doing image masking. First I was using C*GImageMaskCreate()* function for masking but now I am using your solution which you had posted for masking. My problem is it works fine on simulator but on device it is not transparent and it gives rectangle of mask image at background. The following is my code. Now tell me what I have to do? Thanks.

CGContextRef mainViewContentContext; CGColorSpaceRef colorSpace; UIImage *orgImage=[UIImage imageNamed:@"orgimage.png"]; CGImageRef img = [orgImage CGImage];

colorSpace = CGColorSpaceCreateDeviceRGB();

mainViewContentContext = CGBitmapContextCreate (NULL, width, height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease(colorSpace);

if (mainViewContentContext==NULL)
    return NULL;

CGRect subImageRect; 
CGImageRef tileImage;
subImageRect = CGRectMake(xCord,yCord,width,height);
tileImage = CGImageCreateWithImageInRect(img,subImageRect);

CGImageRef maskImage = mask_image.CGImage;
CGContextClipToMask(mainViewContentContext, CGRectMake(0, 0, width, height), maskImage);
CGContextDrawImage(mainViewContentContext, CGRectMake(0, 0, width, height), tileImage);

CGImageRef mainViewContentBitmapContext = CGBitmapContextCreateImage(mainViewContentContext); CGContextRelease(mainViewContentContext); UIImage *theImage = [UIImage imageWithCGImage:mainViewContentBitmapContext]; CGImageRelease(mainViewContentBitmapContext);

© Stack Overflow or respective owner

Related posts about iphone