iPhone SDK:将图像转换/上传到 SOAP 服务

发布于 2024-09-24 01:15:15 字数 619 浏览 1 评论 0原文

我在将相机图像转换/上传到远程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷默言语 2024-10-01 01:15:15

您不需要将图像转换为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文