カメラから画像をキャプチャした後、別のビューに移動したときに、その画像を自動的に-90度回転させた場合、再度ビューを90度回転させて元の位置に戻すことはできますか?iOSで90度イメージを変更するには?
1
A
答えて
3
imageView.transform = CGAffineTransformMakeRotation(3.14/2);
はここ
+1
imageView! –
0
を助ける必要がありますが参照できるリンクです。
あなたはCGAffineTransform
を使用してそれを行うことができます。
お客様のご質問は、お客様のご質問に応じて十分です。
How to programmatically rotate image by 90 Degrees in iPhone?
は、この情報がお役に立てば幸いです。
0
は、この関数のスケールをチェックアウトし、回転させ、それはあなたが、PI値を使用する必要があります
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
ための助けとなることがあります。
ImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
関連する問題
- 1. 画像を90度、180度または270度回転する
- 2. jQueryでイメージのalt属性を何度も変更するには?
- 3. Androidを90度回転する
- 4. PHP高度なイメージのサイズ変更、iOSのサイズ変更の方法と似ています
- 5. WordpressでイメージURL自体をイメージに変更する方法
- 6. iOS - 画面の色温度を変更する
- 7. WPF XAML IsEnabled状態でイメージの不透明度を変更する
- 8. Androidでイメージにキャンバスの背景を変更するには?
- 9. FCKeditorでイメージのアップロードパス*を動的に変更するには
- 10. jQueryでRaphael SVGイメージを変更する
- 11. jQueryでイメージのサイズを変更する
- 12. イメージをイオンカードでサイズ変更
- 13. イメージをPythonMagickでサイズ変更
- 14. イメージをPHPでサイズ変更
- 15. 線から線を90度描く
- 16. ステップ関数を90度の遷移にする
- 17. イメージの透明度を設定するIOS
- 18. addArcWithCenterに0度のstartAngleを指定すると、90度から開始されるのはなぜですか?
- 19. アンドロイドアプリケーションで背景イメージを変更するには?
- 20. イメージをJavaでサイズ変更するには?
- 21. Silverlight 4でイメージのサイズを変更するには?
- 22. GWTでサイズ変更可能なイメージを作成するには?
- 23. Androidでイメージのサイズを変更するには?
- 24. アンドロイドボタンを右に回転して-90度に合わせる
- 25. iOSクォーツストロークカラーを変更する
- 26. mysqlで一度に複数のテーブルを変更するには?
- 27. 変更SurfaceViewイメージはサムネイル
- 28. レベルプロットでX軸ラベルを90度回転させる方法
- 29. ロスレスJPEG回転(90/180/270度)のJava?
- 30. 要素の背景イメージを変更できる頻度には制限がありますか?
[UIImageを90度回転させるにはどうすればいいですか?](http://stackoverflow.com/questions/1315251/how-to-rotate-a-uimage-90-degrees) – iPhone