UI图像旋转
我在 UIImageView(在 UIScrollView 内)中显示图像,该图像也存储在 CoreData 中。
在界面中,我希望用户能够将图片旋转 90 度。我还希望它保存在 CoreData 中。
我应该在显示屏中旋转什么?滚动视图、uiimageview 还是图像本身? (如果可能的话,我希望旋转具有动画效果)但是我还必须将图片保存到 CoreData。
我考虑过更改图像方向,但此属性是只读的。
I display an image in a UIImageView (within a UIScrollView) which is also stored in CoreData.
In the interface, I want the user to be able to rotate the picture by 90 degrees. I also want it to be saved in CoreData.
What should I rotate in the display? the scrollview, the uiimageview or the image itself? (If possible I would like the rotation to be animated) But then I also have to save the picture to CoreData.
I thought about changing the image orientation but this property is readonly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要仅显示旋转后的图像,您应该旋转 UIImageView。
您可以将一些元数据与图像一起存储在 CoreData 中,说明应应用什么旋转。
某些图像格式具有隐式旋转属性。如果您知道压缩图像数据格式,您可以查找规范并查看它是否支持它。
如果您要实际旋转图像像素,则必须手动执行此操作。您可以创建一个 CGBitmapContext 并通过扰乱变换矩阵将图像绘制到其中旋转,然后从位图中创建一个新图像。
To just display the image rotated, you should rotate the UIImageView.
You could store some metadata along with the image in CoreData saying what rotation should be applied.
Some image formats have an implicit rotation property. If you know the compressed image data format you can look up the specification and see if it supports it.
If you are going to actually rotate the image pixels, you will have to do that manually. You can create a CGBitmapContext and draw the image into it rotated by messing with the transform matrix, then create a new image from the bitmap.
对于动画,通过转换 ImageView 来旋转它:
当您将图像保存到核心数据中时,然后在保存图像之前将该图像旋转到从当前位置开始的 imageViewRotated 角度。
对于旋转 UIImage 使用这个: //记住角度应该以弧度为单位,如果不是弧度则将角度转换为弧度。
我希望这对你有帮助。
For the animation rotate ur ImageView by transforming it:
and when you save the image into core data, then before saving image rotate that image to angle imageViewRotated from current position.
for rotating UIImage use this: //remember the angle should be in Radian, if it is not in radian then convert angle into radian.
I hope this helps you.