UIImage has a read-only property CGImage. I have to read its pixels to a memory block and edit them and then make a new UIImage to replace the old one. I want to know if there is a way bypass the read-only property and edit those pixels directly.
Thanks.
Thanks all. I have found a way to do it. Write a class with those method:
-(void)preProcess:(UIImage*)srcImage {
m_Context = ...// Created by calling CGBitmapContextCreate(...)
...
CGContextDrawImage(m_Context, rect, srcImage.CGImage);
m_Bits = (unsigned char*)CGBitmapContextGetData (mContext);
}
-(void)postProcess {
CGContextRelease(m_Context);
free(m_Bits);
}
-(UIImage*)doProcess:(CGPoint)pt {// just a example
unsigned char* ppxl = m_Bits + ...
// do something...
CGImageRef imRef = CGBitmapContextCreateImage(mContext);
return [UIImage imageWithCGImage:imRef];
}
And preProcess and postProcess are called just once.