There may be a requirement in the project, which will generally be converted to NSString when uploading the server.
So the question is, how does the picture turn to NSString, the picture that has been converted to nsstring and then turned into a picture
In fact, it's very simple, just give us two ways OK
Picture to String-(NSString *) Uiimagetobase64str: (UIImage *) image{ NSData *data = uiimagejpegrepresentation (image, 1.0f); nsstring *encodedimagestr = [data base64encodedstringwithoptions:nsdatabase64encoding64characterlinelength]; return ENCODEDIMAGESTR;}
string to Picture-(UIImage *) Base64strtouiimage: (NSString *) _encodedimagestr{ nsdata *_decodedimagedata = [[NSData] Alloc] initwithbase64encoding:_encodedimagestr]; UIImage *_decodedimage = [UIImage imagewithdata:_decodedimagedata]; return _decodedimage;}
OK, everybody, you can test it.
Test demo upload to the group space, welcome to download.
UIImage and Base64 cross-transfer. zip |
Apple Development Group: 414319235 Welcome to join the Welcome discussion question
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS UIImage Turn NSString