简体   繁体   中英

Objective-c Base64 NSString to NSData conversion

I am trying to load in a very large string that is a base64 encoded PNG into NSData to create a UIImage on the fly. I can get the image generated by it is very distorted. Am I doing this correctly? I am also using SBJson in this example.

// Data is the NSData loaded in from the web
NSString *responseValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *successData = [(NSDictionary*)[responseValue JSONValue] objectForKey:@"MapFlightResult"];
NSData *pngData = [[NSData alloc] initWithBase64EncodedString:successData options:1];
UIImage *map = [UIImage imageWithData:mapData];
[imageView setImage:map];

我相信您的问题是,您没有将base64编码的字符串发送到initWithBase64EncodedString

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM