2010-09-14 45 views
0

我在將攝像機圖像轉換/上傳到遠程SOAP Web服務時遇到了問題。iPhone SDK:將圖像轉換/上傳到SOAP服務

下面是將圖像轉換爲字節數組的代碼:

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]]; 

難道我這個圖像轉換爲字節數組正確?

任何幫助表示讚賞。

回答

0

您不應該需要將圖像轉換爲NSString才能將其發佈到Web服務,只需將其發佈到NSData。

如果您使用的是NSMutableURLRequest,那麼您將使用- (void)setHTTPBody:(NSData *)data使用由UIImagePNGRepresentation或UIImageJPEGRepresentation返回的值。有關更多信息,請參閱Apple's documentation of the NSMutableURLRequest class

+0

這就是我的想法,但似乎並不奏效。 Web服務期望以base64Binary格式接收圖像數據。那是對的嗎? – dbarrett 2010-09-17 18:19:57

相關問題