-(void)createImages
{
// Load the alpha image, which is just the same Ship.png image used in the clipping demo
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"Ship.png" ofType:nil];
UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
_alphaImage = CGImageRetain(img.CGImage);
// To show the difference with an image mask, we take the above image and process it to extract
// the alpha channel as a mask.
// Allocate data
NSMutableData *data = [NSMutableData dataWithLength:90 * 90 * 1];
// Create a bitmap context
CGContextRef context = CGBitmapContextCreate([data mutableBytes], 90, 90, 8, 90, NULL, (CGBitmapInfo)kCGImageAlphaOnly);
// Set the blend mode to copy to avoid any alteration of the source data
CGContextSetBlendMode(context, kCGBlendModeCopy);
// Draw the image to extract the alpha channel
CGContextDrawImage(context, CGRectMake(0.0, 0.
iOS:获取图片Alpha图片
最新推荐文章于 2022-02-12 17:12:55 发布
这段代码展示了如何在iOS中从图片`Ship.png`加载Alpha通道,并将其转化为图像遮罩。通过创建位图上下文,提取并保存Alpha信息到NSData对象,然后创建一个新的图像遮罩,用于后续的图像处理操作。
摘要由CSDN通过智能技术生成