如何在iphone中将图像转换为数据

如何在iphone中将图像转换为数据,iphone,Iphone,有人能告诉我如何在iphone中将图像(PNG)转换成数据吗 NSData* pictureData = UIImagePNGRepresentation(image); 这里image是一个UIImage对象如果您想从包中获取数据,那么它类似于您为它指定的路径。 下面是通过这种方式从PNG图像获取数据的代码 NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]; NSData *myDa

有人能告诉我如何在iphone中将图像(PNG)转换成数据吗

NSData* pictureData = UIImagePNGRepresentation(image);

这里image是一个UIImage对象

如果您想从包中获取数据,那么它类似于您为它指定的路径。 下面是通过这种方式从PNG图像获取数据的代码

NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];

这比我想象的要容易得多!
NSData* pictureData = UIImagePNGRepresentation(image); // PNG conversion 
NSData* pictureData = UIImageJPEGRepresentation(image); //JPEG conversion