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

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

iOS照片缩略图thumbnail模糊问题

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

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

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

iOS照片缩略图thumbnail模糊问题

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

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

这时为

iOS照片缩略图thumbnail模糊问题

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

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

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

iOS照片缩略图thumbnail模糊问题

相关文章:

  • 2022-01-06
  • 2022-12-23
  • 2021-05-24
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
猜你喜欢
  • 2021-07-07
  • 2021-07-21
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-11-22
相关资源
相似解决方案