UIImageJPEGRepresentation和糟糕的图像

时间:2013-01-22 22:17:51

标签: xcode image 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];

感谢瑞吉斯

1 个答案:

答案 0 :(得分:0)

对不起,为了在我的网络服务器上工作,我使用realVnc。 RealVnc的设置被设置为低分辨率!!!我确实更改了设置以获得更好的分辨率,现在问题解决了!