UIImagePickerController 图像方向
谁能告诉我如何使用 UIImagePickerController (相机和相册)委托确定图像的方向,相应地旋转并将其分配给 UIImageView?
Can anyone tell me how to use the UIImagePickerController (camera and album) delegates determine the image's orientation, rotate accordingly, and assign it to a UIImageView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
沃德康的答案部分不正确——现代相机在拍照时会在图像中加入明确的方向。这种情况已经常见了大约 5 年多了。
我之前使用过此答案中的代码,通过直接从图片中读取“方向”信息来进行旋转:
UIImagePickerController 相机预览在横向应用程序中为纵向
Vodkhang's answer is partially incorrect - modern cameras put an explicit orientation into the image when they take the photo. This has been common for about 5+ years now.
I've previously used the code in this answer to do the rotation by reading the "orientation" info direct from the picture:
UIImagePickerController camera preview is portrait in landscape app
注意:
UIImageView
读取imageOrientation
属性并相应地显示UIImage
。Note:
UIImageView
reads theimageOrientation
property and displaysUIImage
accordingly.不,UIImagePickerController 无法显式执行此操作。
如果你想根据图像的内容来确定。这是一个难题。在不了解图像内部内容的情况下,如何确定图像的方向?
我可以建议您一个技巧,检查返回图像的宽度和长度,看看它是纵向还是横向。对于旋转图像,外面有一些库和代码,但我没有尝试太多。你可以看看这个博客
No, UIImagePickerController cannot do it explicitly.
If you want to determine based on image's content. It is kind of hard problem. How can you determine an image's orientation without understanding the content inside of it?
I can suggest you a trick that you examine the width and the length of the returned image and see if it is portrait or landscape. For rotating the image, there are some libraries and codes outside but I didn't try them much. You can take a look at this blog