我希望能够从应用程序包中的 png 创建一个没有 alpha 的灰度图像。
这行得通,我创建了一个图像:
// Create graphics context the size of the overlapping rectangle
UIGraphicsBeginImageContext(rectangleOfOverlap.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// More stuff
CGContextDrawImage(ctx, drawRect2, [UIImage imageNamed:@"Image 01.png"].CGImage);
// Create the new UIImage from the context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
然而,生成的图像是每像素 32 位并且有一个 alpha 通道,所以当我使用 CGCreateImageWithMask 时它不起作用。我已经尝试创建一个位图上下文:
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef ctx =CGBitmapContextCreate(nil, rectangleOfOverlap.size.width, rectangleOfOverlap.size.height, 8, rectangleOfOverlap.size.width , colorSpace, kCGImageAlphaNone);
UIGraphicsGetImageFromCurrentImageContext 返回零并且不创建结果图像。我在这里做一些愚蠢的事情吗?
任何帮助将不胜感激。
问候
戴夫