目标C,转换UIImage的数据为const的无符号字符myArry [100]
我需要一个UIImage转换成的东西相匹配的以下类型:
const unsigned char myImg[6300] = { 0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,
0x0,0xff,0xff,0x0,0x0,0xff,0xff,0xff,0xff,0x0,0x0,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0x0,0x0,0xff,0xff, etc etc etc }
我读过NSData的文档和尝试:
self.animalImage = [UIImage imageNamed:@"animal.png"];
self.animalData = UIImagePNGRepresentation(self.animalImage);
NSUInteger size = [self.animalData length]/sizeof(unsigned char);
unsigned char* array = (unsigned char*) [self.animalData bytes];
但结果是垃圾还是零,我需要它完全符合上述格式。有什么想法吗?预先感谢任何提示!
你真的想要PNG数据吗?或者你正在寻找你的图像的位图表示? – 2012-01-12 22:36:36
您的格式示例应该是什么?你是否想要某种二进制图像,其中每个像素是0或255,还是你想要标准的RGB位图表示,其中每个字节的三倍是像素的红色,绿色和蓝色值?现在你得到的是表示图像的PNG(即压缩)版本的字节。 – UIAdam 2012-01-12 22:40:03