我的應用程序允許用戶在相機中拍攝照片/或從他的照片庫中進行選擇。執行http post後的UIImage圖像分辨率
我想投稿的圖像是在650X550
分辨率不過,我看到:
此代碼後的尺寸爲320X480
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
chosenImage = image;
NSLog(@"The widht is %f",image.size.width);
NSLog(@"The height is %f",image.size.height);
}
當我提交有關影像這樣的 - 我檢索它在服務器端1024X480
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://myurl/upload/"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[request setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSData *imageData = UIImageJPEGRepresentation(appDelegate.chosenImage, 0.5);
// file
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"file\"; filename=\"iphone.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// close form
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// set request body
[request setHTTPBody:body];
我想檢索它作爲650X550 - 我在objcetive-c聲明的大小 - 我的代碼在服務器端
當我嘗試提交給我的後端代碼與常規的HTML頁面 - 它發送原始大小的圖像,而不是1024X480。
如何實現以原始尺寸檢索圖像?
xcode只是一個IDE,這與ide無關:) –
正確。我修復了它 – Dejell