这是我第一次关于图像处理任务。我假定输出图像上的每个像素的索引被表示为如下矩阵:如何在iPhone上的图像上按像素添加颜色?
00 01 02 03 04 05
10 11 12 13 14 15
20 21 22 23 24 25
在输出图像的每个索引我有不同的颜色来绘制上。例如,在索引00处,我有redcolor可用于放置在其他索引等。我的问题是如何将这些颜色绘制到索引中以创建输出图像?
更新
这就是我现在所拥有的:
inputImgAvg //Image for processing
CGContextRef context = UIGraphicsGetCurrentContext();
float yy = groutW/2; // skip over grout on edge
float stride =(int) (tileW + groutW +0.5);
for(int y=0; y<tilesY; y++) { //Number tile in Y direction
float xx = groutW/2 ; // skip over grout on edge
for(int x=0; x<tilesX; x++) {
tileRGB = [inputImgAvg colorAtPixel:CGPointMake(x,y)];
//Right here I'm checking tileRGB with list of available color
//Find out the closest color
//Now i'm just checking with greenColor
// best matching tile is found in idx position in vector;
// scale and copy it into proper location in the output
CGContextSetFillColor(context, CGColorGetComponents([[UIColor greenColor] CGColor]));
但我得到这个错误。你能指出我做错了什么吗?
<Error>: CGContextSetFillColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
为什么有-1? – user1139699 2012-01-26 23:44:00
如果你真的尝试你的任务,然后询问你遇到的具体问题,你会从堆栈溢出中得到最好的回应。 – theTRON 2012-01-26 23:52:03
我认为这个问题可能是你正在寻找的: http://stackoverflow.com/questions/448125/how-to-get-pixel-data-from-a-uiimage-cocoa-touch-or -cgimage-core-graphics – 2012-01-26 23:52:32