iOS照片缩略图thumbnail模糊问题

使用ALAsset获取图片的缩略图,一般都有模糊的问题

[_imageView setImage:[UIImage imageWithCGImage:asset.thumbnail]];

对于这种问题,比较简单的修改方法是使用

[_imageView setImage:[UIImage imageWithCGImage:asset.aspectRatioThumbnail]];

aspectRatioThumbnail获取的是原始照片的缩略图,而不是方图。直接使用的话会出问题

可以看到图片都被拉伸了,比例不协调。可以使之自适应

_imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kThumbnailSize.width, kThumbnailSize.height)];
_imageView.contentMode = UIViewContentModeScaleAspectFill;

这时为

发现图片比例没失调,但格局混乱。这时直接想到的就是对图片进行裁剪,使之大小合适。但还有种更简单的方法,使用遮罩

_imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kThumbnailSize.width, kThumbnailSize.height)];
_imageView.contentMode = UIViewContentModeScaleAspectFill;
_imageView.layer.masksToBounds = YES;

这就能实现类似裁剪的功能,完美解决。

原文地址:https://www.cnblogs.com/Apologize/p/5019875.html