Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 删除UIImageView中的白色背景_Iphone_Crop_Transparent_Uigraphicscontext - Fatal编程技术网

Iphone 删除UIImageView中的白色背景

Iphone 删除UIImageView中的白色背景,iphone,crop,transparent,uigraphicscontext,Iphone,Crop,Transparent,Uigraphicscontext,我正在使用UIBezierPath以白色背景和黑色笔划用手指和触摸端方法绘制线条。我正在使用cgraphicscontext()裁剪图像,效果很好。我想删除白色背景,使其透明。我已经尝试了几种代码,但这些代码对我不起作用。下面的代码使整个图像透明。除黑色笔划外,任何人都可以帮助我使图像透明。提前谢谢。对不起,如果问题已经被问到了 -(UIImage*) makeTransparent : (UIImage*) viewImage { CGImageRef rawImageRef = vi

我正在使用
UIBezierPath
以白色背景和黑色笔划用手指和触摸端方法绘制线条。我正在使用
cgraphicscontext()
裁剪图像,效果很好。我想删除白色背景,使其透明。我已经尝试了几种代码,但这些代码对我不起作用。下面的代码使整个图像透明。除黑色笔划外,任何人都可以帮助我使图像透明。提前谢谢。对不起,如果问题已经被问到了

-(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;
}

您可以使用
UIImageView
来显示
UIImage
,然后只需将BackgroundColor设置为
clearColor
如下所示

        [yourImageView setBackgroundColor:[UIColor clearColor]];

您可以使用
UIImageView
来显示
UIImage
,然后只需将BackgroundColor设置为
clearColor
如下所示

        [yourImageView setBackgroundColor:[UIColor clearColor]];

很抱歉我的错误。裁剪时,我使用的是UIJPEG表示,而不是UIPNGRE表示。它解决了我的问题。对不起。我的错误。裁剪时,我使用的是UIJPEG表示,而不是UIPNGRE表示。它解决了我的问题。