Base64 to transcode pictures and files into strings (inter-transfer)

Source: Internet
Author: User
Tags string back

File Base64 will laterdoubled the rise, for example, a 52kb picture base64 after the string file size is 185kb, in a string back to the picture for 135kb picture to text:
UIImage *_originimage = [UIImage imagenamed:@ "0.jpg"1.0f);   *_encodedimagestr = [_data base64encodedstringwithoptions:nsdatabase64encoding64characterlinelength];[ _encodedimagestr writetofile:@ "/users/singer/documents/0.txt"  atomically: YES encoding:nsutf8stringencoding Error:nil]; NSLog (@ "===encoded image:\n%@", _ENCODEDIMAGESTR);

Text to Picture:
NSString *imagestr = [NSString stringwithcontentsoffile:@"/users/singer/documents/0.txt"encoding:nsutf8stringencoding Error:nil]; NSData*d =[[NSData alloc]initwithbase64encodedstring:imagestr options:nsdatabase64decodingignoreunknowncharacters]; UIImage*image =[UIImage imagewithdata:d]; Uiimageview*imageview = [[Uiimageview alloc]initwithframe:cgrectmake ( -, -, $, $)];imageview.image=image; [Self.view Addsubview:imageview]; [D WriteToFile:@"/users/singer/documents/1111.jpg"Atomically:yes];

Base64 to transcode pictures and files into strings (inter-transfer)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.