我有一个UIImage(Cocoa Touch).从那以后,我很高兴得到一个CGImage或其他你想要的东西.我想写这个函数:
- (int)getRGBAFromImage:(UIImage *)image atX:(int)xx andY:(int)yy {
// [...]
// What do I want to read about to help
// me fill in this bit, here?
// [...]
int result = (red << 24) | (green << 16) | (blue << 8) | alpha;
return result;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
UIImage有一个只读属性CGImage.我必须将其像素读取到内存块并编辑它们,然后创建一个新的UIImage来替换旧的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];
}
Run Code Online (Sandbox Code Playgroud)
preProcess和postProcess只调用一次.
只是想知道如何将径向渐变(点>圆)渲染到新的UIImage(iphone)上.我看到以下内容:
它让我觉得我需要使用CGShadingRef或CGGradientRef,并使用UIImage的'imageWithCGImage'构造函数从CG*转到UIImage ...但我无法弄清楚如何.
任何建议都非常感谢!