简体   繁体   English

iOS UIImage拉伸:如何在较小的UIImageView中放置较大的UIImage而不降低任何质量且没有任何空格

[英]iOS UIImage stretching: How to fit a larger UIImage in a smaller UIImageView without any quality decrease and without any spaces

![enter image description here][1]I am taking a UIImage from UIImagePickerController and showing it in a UIImageView. ![在此处输入图像描述] [1]我从UIImagePickerController获取UIImage并在UIImageView中显示它。 Actually the UIImagePickerController is in full screen and thus the UIImage is also. 实际上UIImagePickerController是全屏的,因此UIImage也是。 But UIImageView is not in full screen because of presence of a header bar. 但由于存在标题栏,UIImageView未全屏显示。

The Image is getting stretched.. 图像越来越紧张..

How do I fix this.. 我该如何解决..

Please help me someone.. 请帮帮我一个人..

THANKS IN ADVANCE..... 提前致谢.....

First image is the image picker screen and second one is where I am displaying the UIImage captured from picker in a UIImageView. 第一个图像是图像选择器屏幕,第二个图像是我在UIImageView中显示从拾取器捕获的UIImage的位置。

![This is my UIImagePickerController][2] ![这是我的UIImagePickerController] [2]

![This is the image after capturing being shown in a UIImageview. ![这是捕获后的图像显示在UIImageview中。 ][3] ] [3]

NOTE: BOTH THE SCREENS ARE IN LANDSCAPE MODE 注意:屏幕两者都处于风景模式

Use this for your UIImageView 将此用于UIImageView

 imageView.contentMode = UIViewContentModeScaleAspectFill;

You won't get any space and with scale preserved. 您将无法获得任何空间并且保留了比例。 However, some part of the image will be clipped off. 但是,图像的某些部分将被剪掉。

If you use: 如果您使用:

imageView.contentMode = UIViewContentModeScaleAspectFit;

There will be some empty space, but scale is preserved. 将有一些空的空间,但保留了比例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM