當我從相機捕捉圖像,然後轉移到另一個視圖,當我在那時忽略該視圖,我的圖像自動旋轉了-90度,那麼我怎樣才能再次旋轉到90度,並將其轉換到原始位置?如何在iOS上將圖像更改爲90度?
1
A
回答
3
imageView.transform = CGAffineTransformMakeRotation(3.14/2);
應該幫助
+1
不是imageView! – 2013-12-17 12:27:51
0
這裏是你可以參考鏈接:
可以使用CGAffineTransform
做到這一點。
這將滿足您的要求,根據您的問題是什麼。
How to programmatically rotate image by 90 Degrees in iPhone?
希望這有助於。
0
退房此功能縮放和旋轉,它可能是幫助你
image = [self scaleAndRotateImage:image];
- (void)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"];
}
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
CGContextScaleCTM(context, -scaleRatio, scaleRatio);
CGContextTranslateCTM(context, -height, 0);
}
else {
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextTranslateCTM(context, 0, -height);
}
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self setRotatedImage:imageCopy];
//return imageCopy;
}
1
必須使用PI值:
ImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
相關問題
- 1. 如何在iOS上將圖像旋轉90度?
- 2. 如何在iOS中將圖像高度和寬度更改爲CGPoint?
- 3. iOS Swift 3圖像左轉90度
- 4. 如何將標籤系列更改爲圖表90°(垂直)的角度c#
- 5. 如何在iOS 6.0中將彩色圖像更改爲黑白圖像?
- 6. ImagePicker將iOS相機圖像旋轉90度
- 7. 如何更改圖像透明度實時在IOS
- 8. 如何將紅色Pin更改爲自定義圖像? iOS
- 9. 爲什麼本地圖像在UIWebView上轉過90度
- 10. 在iOS中將文本旋轉90度
- 11. 如何在點擊時將圖像更改爲其他圖像?
- 12. 如何在iPhone SDK中將瘦圖像更改爲胖圖像?
- 13. 如何在懸停時將圖像更改爲另一圖像
- 14. 如何將numpy數組更改爲灰度opencv圖像
- 15. Python圖像庫:圖像轉過90度?
- 16. 如何將UIImage和圖像數據旋轉90度
- 17. 旋轉90度後,如何將圖像添加到CALayer背面?
- 18. 如何以C爲增量旋轉90度的bmp圖像?
- 19. 在Chrome中旋轉90度的圖像
- 20. 在C中旋轉PPM圖像90度
- 21. 根據其他圖像的位置將圖像旋轉90度
- 22. 如何在圖像處理中將圖像對比度修改爲修改後的自動對比度圖像?
- 23. 旋轉90度/ -90度的圖像模糊jquery rotate
- 24. iOS - 如何將png圖像轉換爲4位位圖灰度?
- 25. 如何僅將圖像上的循環從100更改爲199?
- 26. 如何更改圖像的亮度
- 27. 如何將活動圖像更改爲單獨圖像?
- 28. 如何將圖像更改爲懸停時的其他圖像
- 29. 如何將一個圖像更改爲另一個圖像?
- 30. jquery更改圖像高度更改圖像高度錯誤
可能重複的[如何旋轉UIImage 90度?](http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees) – iPhone 2012-02-17 10:27:18