简体   繁体   English

UIImageView:内容模式宽高比使图像失真

[英]UIImageView: Content Mode Aspect Fit Distorts Image

I'm trying to manually create a grid of images on the iPhone. 我正在尝试在iPhone上手动创建图像网格。

I've placed all my UIImageViews correctly, and they're all linked up correctly to the code. 我已经正确放置了所有UIImageViews,它们都已正确链接到代码。 However, I have one small issue: my images are too big, and therefore, they need downscaling. 但是,我有一个小问题:我的图像太大,因此需要缩小图像。

This shouldn't be much of a problem, as UIImageViews accept the "Aspect Fit" setting as a content mode; 这应该不是什么大问题,因为UIImageViews接受“宽高比”设置作为内容模式。 however, when an image is assigned to the image view, it is clearly slightly blurry and distorted. 但是,将图像分配给图像视图时,它显然会略微模糊和失真。

这是原始尺寸的原始图像:

这是缩略图:

Now, it is quite obvious the second image is messed up in some ways, especially on the player's jersey number. 现在,很明显第二张图片以某种方式被弄乱了 ,尤其是在球员的球衣号码上。

I imagine this has something to do with the resizing algorithm utilized by the SDK; 我想这与SDK使用的调整大小算法有关; should I be resizing images on my own before handing them over to UIImageView, or does the problem lie somewhere else ? 我应该将图像移交给UIImageView 之前自行调整图像的大小,还是问题出在其他地方?

For the sake of completeness, here's the code I'm using, even though I'm certain this isn't where the problem originates from: 为了完整起见,这是我使用的代码,即使我确定这不是问题的根源:

NSString *file = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:file];
image1.image = image;

EDIT: I'm not sure if this is important, but the original image is in the JPG format. 编辑:我不确定这是否重要,但原始图像为JPG格式。

Yes, resizing the image prior to the assignment to its ImageView will reduce the jaggies that you see. 是的,在将图像分配给其ImageView之前调整其大小将减少您看到的锯齿。 To resize a UIImage you can check this answer 要调整UIImage的大小,您可以检查此答案

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

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