iphone - 是否可以在不损失质量的情况下调整 UIImage 的大小?
<p><p>我有一个 UIImage,我把它放在一个 UIImageView 中,它附有一个捏手势识别器,我用它来缩放图像。当我在 UIImageView 中缩放图像时,没有失真并且可以完美缩放。但是,我需要在不在 UIImageView 中时调整 UIImage 的大小,并且当我使用以下代码执行此操作时,结果略有偏差:</p>
<pre><code>CGFloat width = self.imageView.frame.size.width;
CGFloat height = self.imageView.frame.size.height;
UIGraphicsBeginImageContext(CGSizeMake(width, height));
;
UIImage *resizedImage = ;
UIGraphicsEndImageContext();
</code></pre>
<p>如您所见,我从 imageView 获取高度和宽度,因为这是图像需要缩放到的。 </p>
<p>我知道如果 imageView 能够做到这一点,它必须可以完美地缩放它,有没有人碰巧知道我做错了什么?</p>
<p>更新:我附加了图像的前/后(已由用户在 ImageView 中重新缩放)以及使用上述方法调整大小后的外观。 <img src="/image/iOsVt.png" alt="Before"/> <img src="/image/CnpLn.png" alt="After"/> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个:</p>
<pre><code>+ (UIImage*)rescaleImage:(UIImage *)image scaledToSize:(CGRect)newSize {
UIGraphicsBeginImageContext(newSize.size);
;
UIImage *resImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resImage;
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 是否可以在不损失质量的情况下调整 UIImage 的大小?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/8174315/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/8174315/
</a>
</p>
页:
[1]