我正在编码使用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. iPad旋转 - 图像定位
- 2. 相机旋转使用lookAt
- 3. 使用glulookat旋转相机
- 4. 来自相机拍摄图像的图像旋转问题
- 5. 当iPad旋转时旋转视图
- 6. 使用UIGraphicsImageRenderer旋转图像?
- 7. 使用Javascript旋转图像
- 8. 使用CMDeviceMotion旋转图像
- 9. 使用rotateY旋转图像
- 10. 使用openCV旋转图像
- 11. 使用Javascript旋转图像
- 12. 使用css旋转图像
- 13. 旋转图像
- 14. 如何旋转从相机意图接收的位图图像
- 15. 使用相机拍摄时将图像旋转至手机的方向:Android
- 16. Android相机旋转通用
- 17. Android相机旋转
- 18. 相机旋转pointerlockcontrols
- 19. Unity相机旋转
- 20. GLFW - 使用鼠标旋转相机的视图矩阵使其旋转
- 21. iPad视图不旋转
- 22. 设备旋转时旋转相机
- 23. 旋转图像
- 24. 旋转图像
- 25. 旋转图像
- 26. iPad canvas旋转
- 27. - 旋转图像
- 28. ASP图像旋转
- 29. 仅在Samasung设备中从相机单击时图像旋转
- 30. Droid设备 - 不会旋转从相机捕获的图像? (Camera.Parameters)
不可能知道没有一些相关的代码 – 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