2
A
回答
6
要旋轉視圖:
imageView.transform = CGAffineTransformMakeRotation(37.8°);
要旋轉圖像,
- 計算旋轉後圖像佔用的寬度和高度。
- 通過
UIGraphicsBeginImageContext
創建CGContext
。 CGContextRotateCTM(UIGraphicsGetCurrentContext(), 37.8°);
[yourImage drawAtPoint:...];
UIGraphicsGetImageFromCurrentImageContext();
並使用該圖片來代替。- 釋放上下文。
1
是的,看到我的回答這個問題:Question about rotating a slider
要度轉換爲弧度(用於positionInRadians ARG)使用此功能:
CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI/180;};
+0
我只需旋轉圖像,而不是視圖。那可能嗎? –
+0
你不能只將圖像加載到UIImageView並將其添加爲子視圖?否則,我會看到KennyTM已經回答瞭如何獲取UIImage並旋轉以獲得另一個UIImage。 – cidered
1
要旋轉圖像,試試這個:
-(IBAction)rotateImageClick:(id)sender{
UIImage *image2=[[UIImage alloc]init];
image2 = [self imageRotatedByDegrees:self.roateImageView.image deg:(90)]; //Angle by 90 degree
self.roateImageView.image = image2;
imgData= UIImageJPEGRepresentation(image2,0.9f);
}
此方法允許您旋轉圖像的任意量:
- (UIImage *)imageRotatedByDegrees:(UIImage*)oldImage deg:(CGFloat)degrees{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,oldImage.size.width, oldImage.size.height)];
CGAffineTransform t = CGAffineTransformMakeRotation(degrees * M_PI/180);
rotatedViewBox.transform = t;
CGSize rotatedSize = rotatedViewBox.frame.size;
// Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
// Move the origin to the middle of the image so we will rotate and scale around the center.
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
// // Rotate the image context
CGContextRotateCTM(bitmap, (degrees * M_PI/180));
// Now, draw the rotated/scaled image into the context
CGContextScaleCTM(bitmap, 1.0, -1.0);
CGContextDrawImage(bitmap, CGRectMake(-oldImage.size.width/2, -oldImage.size.height/2, oldImage.size.width, oldImage.size.height), [oldImage CGImage]);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
更多信息請參見this link。
相關問題
- 1. 在iPhone中旋轉UIImage
- 2. UIImage旋轉自定義度
- 3. 旋轉UIImage自定義度
- 4. 旋轉UIImage固定角度轉向
- 5. Xamarin UIImage旋轉
- 6. UIImage旋轉軸
- 7. 旋轉UIImage?
- 8. UIImage旋轉
- 9. 如何旋轉90度的UIImage?
- 10. UIIMage視圖旋轉低於90度
- 11. 旋轉時的低像素密度UIImage
- 12. UIImage像素旋轉
- 13. 如何旋轉UIImage
- 14. 幫助旋轉UIImage
- 15. 旋轉UIImage問題
- 16. iPhone - 翻轉UIImage
- 17. iPhone旋轉景觀
- 18. 旋轉UIImage的給予空白的UIImage
- 19. Iphone將IplImage轉換爲UIImage並返回導致旋轉
- 20. 檢測iPhone旋轉旋轉?
- 21. 在drawRect中旋轉UIImage
- 22. 裁剪旋轉的UIImage
- 23. 如何旋轉UIImage或UIImageView?
- 24. 裁剪後UIImage旋轉
- 25. 旋轉UIImage的問題
- 26. 旋轉UIImage問題 - IOS/Swift
- 27. 旋轉和裁剪UIImage
- 28. 旋轉的UIImage的MonoTouch
- 29. UIImage複製結束旋轉
- 30. UIImage在裁剪後旋轉
很好的解釋。謝謝 – Biranchi