圖片和base64字串的互轉

weixin_33935777發表於2016-06-17

UIImage圖片轉成base64字串:

UIImage *_originImage = [UIImage imageNamed:@"full_playlist_hl.png"];

NSData *_data = UIImageJPEGRepresentation(_image, 1.0f);

NSString *_encodedImageStr = [_data base64Encoding];

NSLog(@"===Encoded image:\n%@", _encodedImageStr);

Base64字串轉UIImage圖片:

NSData *_decodedImageData  = [[NSData alloc] initWithBase64Encoding:_encodedImageStr];

UIImage *_decodedImage      = [UIImage imageWithData:_decodedImageData];

NSLog(@"===Decoded image size: %@", NSStringFromCGSize(_decodedImage.size));

相關文章