Hello,
I am currently making a basic image editor for iphone.
I take the CGImageRef
from a UIImage
and create a context for it using the following code
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);
I then loop through the pixels
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;
}
}
and then create a CGImageRef from the context with
CGImageRef imagea = CGBitmapContextCreateImage(Icontext);
and add the CGImage to a UIImage and assign to a UIImageView
The problem is that the change of alpha isn't effecting the resultant image
if I change the colour of the pixels with
IrawData[byteIndex+(0/1/2)]
the colour changes, but I still can't change the alpha of the pixel
Thank you,
nonono