我有一個ByteArray字節數組的UIImage Objective-C的
unsigned char *outputData = (unsigned char *)malloc(sizeof(unsigned char) * w * h * 4);
outputData[y * h * 4 + x * 4 + 0] = all; //alpha value
outputData[y * h * 4 + x * 4 + 1] = red; //red value
outputData[y * h * 4 + x * 4 + 2] = gre; //green value
outputData[y * h * 4 + x * 4 + 3] = blu; //blue value
//h... total image height
//y,x ... current y and x value from the matrix
現在我想這個數據轉換成UIImage的。這是如何運作的?我試過了:
NSData *outdata = [NSData dataWithBytes:outputData length:sizeof(unsigned char) * w * h * 4];
UIImage *newimage = [UIImage imageWithData:outdata];
但是,這似乎不是正確的解決方案。請幫忙。
好的我認爲我解決了它..我發現imageWithData只是創建具有格式(PNG,JPEG)圖像..所以我需要創建一個上下文第一權利? – Marco