2009-12-08 35 views

回答

27
NSData* pictureData = UIImagePNGRepresentation(image); 

这里图像是UIImage对象

+0

这比我想象的更容易令人惊讶! – Will 2012-10-08 09:24:32

1

如果你想GETDATA从图像捆绑,然后其类似只是你指定的路径。 下面是通过这种方式从您的PNG图像获取数据的代码。

NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]; 
NSData *myData = [NSData dataWithContentsOfFile:path]; 
3
NSData* pictureData = UIImagePNGRepresentation(image); // PNG conversion 
NSData* pictureData = UIImageJPEGRepresentation(image); //JPEG conversion