我正在研究一個讓用戶從圖庫中選擇照片的應用程序。我遇到的問題非常奇怪,因爲照片的大小(在存儲方面)會在使用UIImagePickerController拾取時發生更改。UIImagePickerController返回比起源更大的圖像
就我而言,我通過空投獲得了一張照片。圖像大小爲8.7MB。但是當我通過UIImagePickerController選擇相同的圖像時,它會返回〜13MB的圖像。
注意:圖像的分辨率保持不變([3024,4032])。
我創建了一個非常簡單的應用程序來測試這件事。下面是示例代碼:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@end
ViewController.m
#import "ViewController.h"
@implementation ViewController
bool flag = true;
- (void)viewDidAppear:(BOOL)animated {
if (flag) {
flag = false;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[self presentViewController:picker
animated:YES
completion:NULL];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
NSData *temp = UIImageJPEGRepresentation(chosenImage, 1);
NSLog(@"image: %lu", (unsigned long)temp.length);
NSLog(@"image: [%lu, %lu]", (unsigned long)chosenImage.size.width, (unsigned long)chosenImage.size.height);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES
completion:NULL];
}
@end
this is the link to the app,如果你想測試自己。
該zip文件還包含示例照片。
任何幫助表示讚賞。
請添加規定的計算你期望什麼等於什麼。 – danh
這個答案解決了這個問題。 http://stackoverflow.com/a/38475923/1120688 – harshitgupta