這是我第一次關於圖像處理任務。我假定輸出圖像上的每個像素的索引被表示爲如下矩陣:如何在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