アプリバンドル内のpngからアルファなしのグレースケール画像を作成できるようにしたいと思います。
これは機能し、イメージが作成されます。
// 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();
ただし、結果の画像は1ピクセルあたり32ビットで、アルファチャネルがあるため、CGCreateImageWithMaskを使用すると機能しません。このようにビットマップコンテキストを作成しようとしました:
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef ctx =CGBitmapContextCreate(nil, rectangleOfOverlap.size.width, rectangleOfOverlap.size.height, 8, rectangleOfOverlap.size.width , colorSpace, kCGImageAlphaNone);
UIGraphicsGetImageFromCurrentImageContextはゼロを返し、結果の画像は作成されません。私はここで何か馬鹿げたことをしていますか?
どんな助けでも大歓迎です。
よろしく
デイブ