2009-12-18 29 views
0

我以char *形式獲取圖像數據(存儲在sql server上)。我想將這些數據轉換爲NSData以在UIImage視圖中顯示圖像。 char *數據是源圖像的字節數組。 如何將char *轉換爲NSData來顯示以獲取UIImageView中顯示的UIImage實例?char *將NSData顯示在UIImageView中

謝謝..

回答

2

考慮:

unsigned char *myImageData; 
NSUInteger myImageDataLength; 

myImageData是JPEG,PNG或一些其他的UIImage圖像支持的格式,使用:

-(UIImage*)myImage { 
    return [UIImage imageWithData:[NSData dataWithBytes:myImageData length:myImageDataLength]]; 
} 

如果你的字符數據Base64編碼,檢查出http://www.cocoadev.com/index.pl?BaseSixtyFour

我已經完成了這兩個數據從一個Web服務和烤圖像。例如:

// Note hex = ".PNG..", the start of the PNG header. 
static unsigned char myImageData[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a,... }; 

長度是圖像文件的大小,並且可以從圖像文件創建的十六進制值:

hexdump -e ' 16/1 "0x%02x, " "\n"' MyImage.png 
+0

這不是爲我工作... – DivineDesert 2011-08-26 12:55:52