iPhone SDK:将图像转换/上传到 SOAP 服务
我在将相机图像转换/上传到远程 SOAP Web 服务时遇到问题。
这是将图像转换为字节数组的代码:
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (image == nil)
image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
NSString *post_string = [NSString stringWithFormat:@"%@", imageData];
NSData *postData = [post_string dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [[NSString alloc] initWithFormat:@"%d", [postData length]];
我是否正确将此图像转换为字节数组?
任何帮助表示赞赏。
I'm having issues converting/uploading a camera image to a remote SOAP web service.
Here's the code for converting the image to a byte array:
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (image == nil)
image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
NSString *post_string = [NSString stringWithFormat:@"%@", imageData];
NSData *postData = [post_string dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [[NSString alloc] initWithFormat:@"%d", [postData length]];
Am I converting this image to a byte array properly?
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要将图像转换为 NSString 来将其发布到 Web 服务,只需将其发布到 NSData 即可。
如果您使用 NSMutableURLRequest,则可以使用
- (void)setHTTPBody:(NSData *)data
使用 UIImagePNGRepresentation 或 UIImageJPEGRepresentation 返回的值。请参阅 Apple 的文档NSMutableURLRequest 类 了解更多信息。You shouldn't need to convert the image to an NSString to post it to a web service, just to an NSData.
If you are using NSMutableURLRequest, you would then use
- (void)setHTTPBody:(NSData *)data
using the value returned by UIImagePNGRepresentation or UIImageJPEGRepresentation. See Apple's documentation of the NSMutableURLRequest class for more information.