0
嘗試後,我能夠將從相機拍攝的圖像上傳到我的網絡服務器。UIImageJPEGRepresentation和蹩腳的圖像
但我不明白爲什麼圖像質量糟糕,分辨率低,顏色很少。有沒有辦法獲得更好的質量?
這裏是我的代碼:
NSURL *url = [NSURL URLWithString:@"http://localhost"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = UIImageJPEGRepresentation(image, 0.9);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload.php" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageData name:@"file" fileName:@"temp.jpeg" mimeType:@"image/jpeg"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSString *response = [operation responseString];
NSLog(@"response: [%@]",response);
//[MBProgressHUD hideHUDForView:self.view animated:YES];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
//[MBProgressHUD hideHUDForView:self.view animated:YES];
if([operation.response statusCode] == 403)
{
NSLog(@"Upload Failed");
return;
}
NSLog(@"error: %@", [operation error]);
}];
[operation start];
感謝紅塔
您將需要對原始圖像進行一些比較以查看質量下降的發生位置。 UIImageJPEGRepresentation與原始UIImage相比如何?服務器上的版本與UIImageJPEGRepresentation相比如何?除了視覺比較外,還要看它們的像素尺寸和文件大小。 – foundry