【发布时间】:2013-12-03 21:43:05
【问题描述】:
我正在编写一个获取图像和 alpha 值的方法,然后返回具有该 alpha 值的 uiimage。
我找到了一些这样的代码
+ (UIImage *)imageByApplyingAlpha:(UIImage*) originalImage andAlpha:(CGFloat) alpha {
UIGraphicsBeginImageContextWithOptions(originalImage.size, NO, 0.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, originalImage.size.width, originalImage.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextSetAlpha(ctx, alpha);
CGContextDrawImage(ctx, area, originalImage.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
但这仅适用于单个图像。当我使用返回的图像形成 GIF 时,它会生成格式错误的 GIF。
请帮助我找到一种简单的方法来获取带有 alpha 的 UIImage。
谢谢大家!
【问题讨论】:
标签: ios objective-c uiimage alpha