图像数据,iphone Base64的解码问题 [英] Base64 decoding issue with image data-iphone
问题描述
我从基地64 EN codeD串解码图像数据的一些问题。
我使用从以下链接下载base64.h和基础64.m文件
I have some problem for decoding image data from base 64 encoded string. I am using base64.h and base 64.m files downloaded from the following link
http://cdn.imthi.com/ e6cef8 /可湿性粉剂内容/上传/ 2010/08 / base64.zip
这是我的code
[Base64 initialize];
NSData * data = [Base64 decode:imageString];
imgview.image=[UIImage imageWithData:data];
但是,没有在图像视图中显示,
but, nothing displayed in the image view ,
我测试由基64字符串(从调试器控制台获取)与网上基地64日codeR解码,它提供了正确的图像,
我还通过将数据写入这样一个文件测试
I tested by decoding the base 64 string(taken from debugger console) with an online base 64 decoder,It gives correct image, I also tested by writing the data to a file like this
[data writeToFile:imagePath atomically:YES];
它给出了一个JPG文件,但我无法打开图片文件,
它提供了错误信息像
it gives a jpg file but i can't open that image file, it gives error message like
文件test.jpg放在无法打开。
The file "test.jpg" could not be opened.
这可能会损坏或使用的文件格式,preVIEW不承认。
什么是我的code中的问题
谁能帮我.....
"It may be damaged or use a file format that Preview doesn’t recognize." What is the problem with my code Can anyone help me.....
感谢您
推荐答案
尝试不同的基本实施64,我用从一个讨论会的开源项目:
Try a different base 64 implementation, I use the one from colloquy open source project:
#import "NSDataAdditions.h"
/* encoded string to image */
NSString *imageString = @"";
NSData * data = [NSData dataWithBase64EncodedString:imageString];
UIImage *image1 = [UIImage imageWithData:data];
/* image to encoded string, back to image */
imageString = [UIImagePNGRepresentation(image) base64Encoding];
data = [NSData dataWithBase64EncodedString:imageString];
UIImage *image2 = [UIImage imageWithData:data];
获取 NSAdditions
文件:的 NSAdditions.h + NSAdditions。米
这篇关于图像数据,iphone Base64的解码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!