【发布时间】:2010-11-19 20:29:39
【问题描述】:
UIImage 有一个只读属性 CGImage。我必须将其像素读取到内存块并对其进行编辑,然后制作一个新的 UIImage 来替换旧的。我想知道是否有办法绕过只读属性并直接编辑这些像素。
谢谢。
谢谢大家。我找到了一种方法。使用这些方法编写一个类:
-(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];
}
preProcess 和 postProcess 只调用一次。
【问题讨论】:
-
嘿,我已经理解您给出的示例,但是可以在这里发布源代码吗?我也在尝试像提出的问题一样实施。
标签: iphone cocoa cocoa-touch uikit core-graphics