gpt4 book ai didi

iphone - 帮助着色由图像蒙版/边界定义的图层并将图像覆盖在顶部

转载 作者:行者123 更新时间:2023-11-28 17:43:56 25 4
gpt4 key购买 nike

我目前正在为客户试验一个头像创建 iOS 应用程序,在某些时候用户应该可以选择更改项目的颜色。

客户端像往常一样以具有不同 alpha/opacity 值的 .png 格式提供要着色的图库项目,以有效地产生阴影。然而,项目着色的正确最终结果不是屏蔽图像并应用颜色混合,因为透明区域保持原样,而是“填充”由项目的“外部笔划”包围的背景区域,然后在顶部重新绘制图像它使阴影适用于新颜色。

这是我取得的成就:

UIImage *image =  item.image;
UIGraphicsBeginImageContext(image.size);

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);

CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);

CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, 0, -area.size.height);

CGContextSaveGState(context);

// This applies the colorization only on the image mask
//CGContextClipToMask(context, area, image.CGImage);

[[UIColor redColor] set];
CGContextFillRect(context, area);

CGContextRestoreGState(context);

CGContextSetBlendMode(context, kCGBlendModeNormal);

CGContextDrawImage(context, area, image.CGImage);

UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

item.image = coloredImg;

产生以下结果。

http://dl.dropbox.com/u/1237004/Screen%20shot%202011-07-15%20at%207.53.50%20%CE%BC.%CE%BC..png

这基本上接近我真正想要实现的,除了裤子外面的红色区域扩大。

那怎么可能消除那部分呢?我正在考虑将 alpha 值减小到图像 mask 未定义的区域或类似的东西,但无法接近解决方案。

谢谢大家的建议。

注意:截图中显示的项目是 WeeMee 头像创建应用程序的一部分,未在我们的应用程序中使用,而是我实验的一部分,所有权利属于其各自所有者

最佳答案

你需要做的是设置一个剪切路径,并指示CG只填充内部区域。如果您已经在绘制定义裤子的路径,这对您来说应该是微不足道的。

请参阅本教程: tutorial

根据评论更新:

Masking an image

关于iphone - 帮助着色由图像蒙版/边界定义的图层并将图像覆盖在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6966645/

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