【发布时间】:2023-04-03 10:00:02
【问题描述】:
我需要获取一个 UIImage 并添加一个半透明层以生成一个新的 UIImage。我想我已经接近了,但还是有问题。这是我的代码:
- (UIImage*) addLayerTo:(UIImage*)source
{
CGSize size = [source size];
UIGraphicsBeginImageContext(size);
CGRect rect = CGRectMake(0, 0, size.width, size.height);
[source drawInRect:rect blendMode:kCGBlendModeNormal alpha:0.18];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 0.2, 0.5, 0.1, 0.18);
CGContextFillRect(context, rect);
UIImage *testImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return testImg;
}
【问题讨论】:
-
怎么了?你看到了什么你不希望看到的?你想看什么?
标签: ios objective-c uiimage core-graphics alpha