gpt4 book ai didi

ios - Tint an Image(必须有更简单的方法)

转载 作者:行者123 更新时间:2023-11-29 02:43:37 25 4
gpt4 key购买 nike

我看过人们用来给图像着色的各种方法(我想应用红色层),而我唯一要使用的方法非常复杂。有没有更简单的方法?

        // 1. Tint the Image
NSString *name = @"Skyline.png";
UIImage *imgBottomCrop = [UIImage imageNamed:name];
// begin a new image context, to draw our colored image onto
UIGraphicsBeginImageContext(imgBottomCrop.size);
// get a reference to that context we created
CGContextRef context = UIGraphicsGetCurrentContext();
// set the fill color
[[UIColor redColor] setFill];
// translate/flip the graphics context (for transforming from CG* coords to UI* coords
CGContextTranslateCTM(context, 0, imgBottomCrop.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// set the blend mode to color burn, and the original image
CGContextSetBlendMode(context, kCGBlendModeColorBurn);
CGRect rectBottomCrop = CGRectMake(0, 0, img.size.width, img.size.height);
CGContextDrawImage(context, rectBottomCrop, imgBottomCrop.CGImage);
// set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
CGContextClipToMask(context, rectBottomCrop, imgBottomCrop.CGImage);
CGContextAddRect(context, rectBottomCrop);
CGContextDrawPath(context,kCGPathFill);
// generate a new UIImage from the graphics context we drew onto
UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Display Image
displayPicture2.image = coloredImg;

最佳答案

如果图像是静态的(在应用程序运行时不会改变),最简单的方法是存储另一个图像并加载它。

如果它不是静态的 - 你就做对了。我能想到的另一种方法是存储一个半透明的红色图像并将其显示在您的图像上。

关于ios - Tint an Image(必须有更简单的方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25420885/

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