UIImage转换成NSData后需要先将NSData转成BASE64
View Code
1 //To convert an image to string you need a method to convert NSData to a base64Encoded string and back (lots of examples here). The easiest ones to use are categories on NSData so you can do something like this:
2
3 UIImage* pic =[UIImage imageNamed:@"sample.png"];
4 NSData* pictureData =UIImagePNGRepresentation(pic);
5 NSString* pictureDataString =[pictureData base64Encoding];
6
7 //To go the other way you need a reverse converter:
8
9 UIImage* image =[UIImage imageWithData:[NSData
10 dataFromBase64EncodedString: pictureDataString]];