UIImageView中的宽高比 [英] Aspect ratio in UIImageView

查看:208
本文介绍了UIImageView中的宽高比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有应用程序,可以添加相机或画廊的照片。添加每张照片后,在 UIImageView 中显示。但他们表现出不好的宽高比。照片扩展到 UIImageView的尺寸。

I got app which can add photo from camera or gallery. After adding each photo showes in UIImageView. But they show with bad aspect ratio. Photoes are extended on UIImageView's size.

如何以实际宽高比显示照片?

How can i show photoes with their real aspect ration?

UPD和小图片怎么样?如果用户将添加非常小的图片,这张图片将在 UIImageView 的所有区域调整大小。如何以实际尺寸显示这些图片?

UPD and what about small pictures? if user will add really small picture, this picture will resize on all area of UIImageView. How show this pictures in real size?

推荐答案

执行 myImageView.contentMode = UIViewContentModeScaleAspectFit; 是一种选择。

但这还不够,因为它改变了图像的纵横比,但它并没有改变源图像。

But it isn't enough because it changes the aspect ratio of the image, but it doesn't change the source image.

唯一的方法是使用 UIGraphicsImageContext ,如下所述:
使用宽高比调整UIImage的大小?

The only way to do that is to use the UIGraphicsImageContext as explained there: Resize UIImage with aspect ratio?

这篇关于UIImageView中的宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆