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];
精彩评论