【发布时间】:2011-07-18 20:31:26
【问题描述】:
我正在使用 UIImageJPEGRepresentation(image, 1.0) 将图像转换为 NSdata,然后使用 base64 辅助类将其编码为 base64
NSString *imageOne = [self encodeBase64WithData:[imageDict objectForKey:@"ImageOne"]];
最后使用 post 方法作为 json 参数将其发送到服务器,并在服务器端使用 php 方法对其进行解码。
/* encode & write data (binary) */
$ifp = fopen($imageNameWithPath, "wb" );
fwrite($ifp, base64_decode($base64ImageString));
fclose($ifp);
解码后,我将文件保存为 jpeg 图像,并以适当的大小和扩展名创建文件,但问题是当我打开它时,我得到的图像尺寸为 0X0 ..(问题就在这里)
服务器端脚本是正确的,因为我们的 android 开发人员也在发送 base64string,并且图像保存为具有适当大小和尺寸的 jpeg。
此问题仅在发送到服务器进行解码时来自 iphone 端。我已经使用我的 base64 辅助类对图像进行了解码,它在我的 iPhone 设备上运行良好。
UIImageView *viewImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData: [self decodeBase64WithString:[registerDataDict objectForKey:@"imageOne"]]]];
[self.view addSubview:viewImage];
我遵循的过程在设备上是否正确,还是我需要更改某些内容?帮助将不胜感激。
【问题讨论】: