我正在編碼使用iPad的相機將照片添加到我的應用程序。 我的應用程序是縱向顯示,相機以縱向顯示,但添加到我的應用程序時,相機拍攝的圖像正在旋轉90度。當保存到照片專輯時,它很好。爲什麼圖像在我的應用程序中旋轉?iPad - 使用相機 - 圖像旋轉
1
A
回答
0
海,我發現只需添加一行檢查這個代碼另一種解決方案..
編輯:這是類似的(幾乎相同的)答案在你給出的鏈接.. Sorry..I沒有充分注意到它: (
- (void) imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)imageInfo {
// Images from the camera are always in landscape, so rotate
UIImage *image = [self scaleAndRotateImage: [imageInfo objectForKey:UIImagePickerControllerOriginalImage]];
//then save the image to photo gallery or wherever
}
- (UIImage *) scaleAndRotateImage: (UIImage *)image
{
int kMaxResolution = 320; // Or whatever
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
if (width > kMaxResolution || height > kMaxResolution) {
CGFloat ratio = width/height;
if (ratio > 1) {
bounds.size.width = kMaxResolution;
bounds.size.height = bounds.size.width/ratio;
}
else {
bounds.size.height = kMaxResolution;
bounds.size.width = bounds.size.height * ratio;
}
}
CGFloat scaleRatio = bounds.size.width/width;
CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
CGFloat boundHeight;
UIImageOrientation orient = image.imageOrientation;
switch(orient) {
case UIImageOrientationUp: //EXIF = 1
transform = CGAffineTransformIdentity;
break;
case UIImageOrientationUpMirrored: //EXIF = 2
transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
break;
case UIImageOrientationDown: //EXIF = 3
transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height);
transform = CGAffineTransformRotate(transform, M_PI);
break;
case UIImageOrientationDownMirrored: //EXIF = 4
transform = CGAffineTransformMakeTranslation(0.0, imageSize.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
break;
case UIImageOrientationLeftMirrored: //EXIF = 5
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0);
break;
case UIImageOrientationLeft: //EXIF = 6
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(0.0, imageSize.width);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0);
break;
case UIImageOrientationRightMirrored: //EXIF = 7
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeScale(-1.0, 1.0);
transform = CGAffineTransformRotate(transform, M_PI/2.0);
break;
case UIImageOrientationRight: //EXIF = 8
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0);
transform = CGAffineTransformRotate(transform, M_PI/2.0);
break;
default:
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];
}
+0
其中是「scaleAndRotateImage」方法? – Satyam 2012-06-16 09:55:01
+0
其實我從這個鏈接中得到了方法https://discussions.apple.com/thread/1537011?start=0&tstart=0 – 2012-06-16 11:09:28
相關問題
- 1. Android相機圖像隨機旋轉
- 2. iPad旋轉 - 圖像定位
- 3. 相機像素旋轉
- 4. 如何旋轉相機 - 相機旋轉
- 5. 使用glulookat旋轉相機
- 6. 相機旋轉使用lookAt
- 7. ZBarReaderViewController相機旋轉
- 8. 如果相機旋轉,則相機的圖像爲空
- 9. 相機旋轉
- 10. 來自相機拍攝圖像的圖像旋轉問題
- 11. 肖像FormSheet旋轉IPad
- 12. iPad - 「放大」肖像旋轉
- 13. 當iPad旋轉時旋轉視圖
- 14. 使用javascript旋轉圖像
- 15. 使用rotateY旋轉圖像
- 16. 使用pixelbender旋轉圖像
- 17. 使用GDI +旋轉圖像+
- 18. 使用Javascript旋轉圖像
- 19. 使用旋轉圖像
- 20. 使用Javascript旋轉圖像
- 21. 使用UIGraphicsImageRenderer旋轉圖像?
- 22. 使用openCV旋轉圖像
- 23. 使用pygame旋轉圖像
- 24. 使用UISlider旋轉圖像?
- 25. 使用CGAffineTransformMakeRotation旋轉圖像
- 26. 使用CMDeviceMotion旋轉圖像
- 27. 使用css旋轉圖像
- 28. 旋轉圖像
- 29. 如何旋轉從相機意圖接收的位圖圖像
- 30. 使用圖像中心作爲旋轉軸旋轉圖像
不可能知道沒有一些相關的代碼 – danielbeard 2012-04-11 08:04:58
我發現從URL答案:http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-應用程序 – Satyam 2012-04-11 08:11:47
我從相機中選取圖片時出現同樣的問題,圖片旋轉請幫助我 – SampathKumar 2013-05-09 07:21:37