2013-07-17 24 views
1

在我正在其中一個應用程序中使用的SDK中,有一些圖像。這些圖片不僅列爲圖像文件,但作爲hexedecimal編碼字符串,如:如何將透明PNG圖像轉換爲十六進制字符串?

unsigned char MASTCloseButton_png[] = { 
    0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 
    0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 
    0x08, 0x06, 0x00, 0x00, 0x00, 0xa8, 0x86, 0x3b, 0x1e, 0x00, 0x00, 0x00, 
    0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x2e, 0x23, 0x00, 0x00, 0x2e, 
    0x23, 0x01, 0x78, 0xa5, 0x3f, 0x76, 0x00, 0x00, 0x0a, 0x4d, 0x69, 0x43, 
}; 

不,我想這個SDK內調整這個形象,但不幸的是,我不知道怎麼我.png文件轉換成上面列出的十六進制字符串。

是否有任何工具將我的.png圖像(透明)轉換爲十六進制字符串?

回答

1

嘗試用下面的代碼,可能對您會有所幫助:

NSData *imageData = [[NSData alloc]initWithData:UIImagePNGRepresentation(myImage.image)]; 
NSString *imageStr = [GTMBase64 stringByEncodingData:imageData]; 

或後續:

http://kelp.phate.org/2012/05/high-performance-hex-encode-in.html

+0

http://stackoverflow.com/questions/12309158/objective-c - 如何對正確編碼,十六進制到圖像文件 – iPatel

相關問題