我使用尺寸为80X80的imagview来显示大图像(1024 X 780)。
将大图像放入图像视图时,图像看起来被压缩,压缩的东西不像质量图像。
我的问题是,如何将大图像制作成与原始图像一样好的小图像?
答案 0 :(得分:1)
在图片视图中,请将 imageview.mode 设为中心,而不是缩放以适合或任何其他。 我相信这会将你的任何缩放图像放在80x80维度的最好的质量中。
答案 1 :(得分:1)
在这种情况下,您应该对想要在ImageView中显示的图像进行适当的缩放
- (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize
{
UIImage *sourceImage = chosenImage;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (CGSizeEqualToSize(imageSize, targetSize) == NO) {
CGFloat widthFactor = targetWidth / width;
CGFloat heightFactor = targetHeight / height;
if (widthFactor < heightFactor)
scaleFactor = widthFactor;
else
scaleFactor = heightFactor;
scaledWidth = width * scaleFactor*1;
scaledHeight = height * scaleFactor;
// center the image
if (widthFactor < heightFactor) {
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
} else if (widthFactor > heightFactor) {
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
UIGraphicsBeginImageContext(targetSize);
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width = scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage ;
}
答案 2 :(得分:1)
[imageView setContentMode:UIViewContentModeScaleAspectFill];
但是,您应该考虑调整图像大小并将其保存在磁盘上,如果您想再使用它一次。 要调整图像大小:
The simplest way to resize an UIImage?
UIImage resize (Scale proportion)
等。
答案 3 :(得分:0)
从1034x780到80x80几乎不可能保持质量,因为没有足够的空间来捕捉所有细节。
您可以尝试缩放它:
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
答案 4 :(得分:0)
您可以设置图片模式[imageView setContentMode:UIViewContentModeScaleAspectFill];
imageView.autoresizingMask =(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[imageView setClipsToBounds:YES];