gpt4 book ai didi

iphone - 如何屏蔽 UIImage 以使白色在 iphone 上变得透明?

转载 作者:行者123 更新时间:2023-12-03 21:00:13 25 4
gpt4 key购买 nike

我有一个具有白色背景的 UIImage(由用户绘图生成)。我想让该图像的白色部分透明。我还想将其保存为 PNG 文件。

我在论坛上浏览过,但不知道如何正确遮盖图像。有人尝试过吗?

谢谢。

最佳答案

尝试这样的事情......

CGImageRef myMaskedImage = [myImage CGImage];
const float whiteMask[6] = { 255,255,255, 255,255,255 };
CGImageRef myColorMaskedImage = CGImageCreateWithMaskingColors(image, whiteMask);

CGDataProviderRef provider;
CGImageRef myPngImage = CGImageCreateWithPNGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt: 72], kCGImagePropertyDPIHeight, [NSNumber numberWithInt: 72], kCGImagePropertyDPIWidth, nil];
CGImageDestinationRef destRef = CGImageDestinationCreateWithURL ((CFURLRef)outPath, (CFStringRef)@"image.png" , 1, NULL);
CGImageDestinationAddImage(destRef, myPngImage, (CFDictionaryRef)options);
CGImageDestinationFinalize(destRef);
CGRelease(destRef);

CGImageRelease(myColorMaskedImage);
CGImageRelease(myPngImage);

来自相当冗长的Quartz2d Programming Guidethis mailing list message .

关于iphone - 如何屏蔽 UIImage 以使白色在 iphone 上变得透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1108255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com