사용자가 갤러리에서 사진을 선택할 수있는 앱을 개발 중입니다. 내가 직면하고있는 문제는 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