Reputation: 113
I am using UIBezierPath
to draw the lines in white background and black stroke using fingers and the touch end method I am cropping the image using CGGraphicsContext()
and which is working fine. I would like to remove the white background and make it as transparent. I have tried several codes and which is not working to me. The below code makes the entire image transparent. Any one can help me to make the image as transparent except the black stroke. Thanks in advance. Sorry if the question is already asked.
-(UIImage*) makeTransparent : (UIImage*) viewImage
{
CGImageRef rawImageRef = viewImage.CGImage;
const float colorMasking[6] = {255, 255, 255, 255, 255, 255};
UIGraphicsBeginImageContext(viewImage.size);
CGImageRef maskedImageRef = CGImageCreateWithMaskingColors(rawImageRef, colorMasking);
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0.0, viewImage.size.height);
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, viewImage.size.width, viewImage.size.height), maskedImageRef);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRelease(maskedImageRef);
UIGraphicsEndImageContext();
return newImage;
}
Upvotes: 0
Views: 2412
Reputation: 20551
you use UIImageView
for display UIImage
then just set BackgroundColor to clearColor
like bellow...
[yourImageView setBackgroundColor:[UIColor clearColor]];
Upvotes: 3