开发者

How to convert an image to data in iphone

can anyone t开发者_JAVA百科ell me how to convert an image(PNG) to data in iphone


NSData* pictureData = UIImagePNGRepresentation(image);

here image is an UIImage object


NSData* pictureData = UIImagePNGRepresentation(image); // PNG conversion 
NSData* pictureData = UIImageJPEGRepresentation(image); //JPEG conversion


If you want to getdata from image from bundle then its similar just you specify the path for it. Below is the code to get data from your PNG image by this way.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜