2013-01-22 59 views
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]; 

感謝紅塔

+0

您將需要對原始圖像進行一些比較以查看質量下降的發生位置。 UIImageJPEGRepresentation與原始UIImage相比如何?服務器上的版本與UIImageJPEGRepresentation相比如何?除了視覺比較外,還要看它們的像素尺寸和文件大小。 – foundry

回答

0

對不起,爲了我的web服務器工作,我使用RealVNC的傢伙。 RealVnc的設置被設置爲低分辨率!我確實改變了設置以獲得更好的解決方案,現在問題解決了!

相關問題