문제

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;
}
도움이 되었습니까?

해결책

you use UIImageView for display UIImage then just set BackgroundColor to clearColor like bellow...

        [yourImageView setBackgroundColor:[UIColor clearColor]];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top