現在、iPhone用の基本的な画像エディターを作成しています。
CGImageRef
a からを取得UIImage
し、次のコードを使用してそのコンテキストを作成します
origImage = result.CGImage;
Iheight = CGImageGetHeight(origImage);
Iwidth = CGImageGetWidth(origImage);
IcolorSpace = CGColorSpaceCreateDeviceRGB();
IrawData = malloc(Iheight * Iwidth * 4);
IbytesPerPixel = 4;
IbytesPerRow = IbytesPerPixel * Iwidth;
IbitsPerComponent = 8;
Icontext = CGBitmapContextCreate(IrawData, Iwidth, Iheight, IbitsPerComponent,
IbytesPerRow, IcolorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big
);
//[bytesPerRow release];
CGContextSetBlendMode(Icontext, kCGBlendModeCopy);
CGContextDrawImage(Icontext, CGRectMake(0,0,Iwidth,Iheight), origImage);
次に、ピクセルをループします
for (int x=0; x<Iwidth; x++) {
for (int y=0; y<Iheight; y++) {
//and set the alpha component to 0
int byteIndex = (y*IbytesPerRow) + x*IbytesPerPixel;
IrawData[byteIndex+3] = 0;
}
}
次に、コンテキストからCGImageRefを作成します
CGImageRef imagea = CGBitmapContextCreateImage(Icontext);
CGImage を UIImage に追加し、UIImageView に割り当てます
問題は、アルファの変更が結果の画像に影響を与えていないことです
ピクセルの色を変更すると
IrawData[byteIndex+(0/1/2)]
色は変わりますが、ピクセルのアルファはまだ変更できません
ありがとうございました、
ダメダメダメ