我使用以下代码裁剪图像,使其适合某些固定大小(例如:100 * 100)
if(newSize.width == Thumbnail_Size) // Thumbnail_Size 100.0
{
CGFloat side = width;
if(width > height)
{
side = height;
}
CGRect croppedRect = CGRectMake(0, 0, side, side);
CGImageRef croppedImage = CGImageCreateWithImageInRect(image.CGImage, croppedRect);
newImage = [[UIImage alloc] initWithCGImage:croppedImage];
if(newImage == nil) NSLog(@"could not scale image");
return newImage ;
}
但图像质量不佳。图像显示在下面的屏幕截图中:
我已将imageview的contentmode设置为UIViewContentModeScaleAspectFit
[imageView setContentMode:UIViewContentModeScaleAspectFit];
我还需要做些什么才能保持裁剪图像的质量?