我想压缩图像质量而不重新调整尺寸。我已经经历了许多与压缩和重新调整大小相关的帖子,但我没有得到我正在寻找的确切内容。我正在使用此代码:
- (UIImage *)compressImage:(UIImage *)image withCompressionFactor:(int)compressionFactor
{
double factor = 1.0;
double adjustment = 1.0/ sqrt(2.0);
CGSize size = image.size;
CGSize currentSize = size;
UIImage *currentImage = image;
NSData *imageData;
int requiredLength;
imageData = UIImagePNGRepresentation(image);
requiredLength = imageData.length/compressionFactor; // (compressionfactor = 3)
while( imageData.length >= requiredLength)
{
factor *= adjustment;
currentSize = CGSizeMake(roundf(size.width * factor), roundf(size.height * factor));
currentImage = [image resizedImage:currentSize interpolationQuality:0.1];
imageData = UIImagePNGRepresentation(currentImage);
}
return currentImage;
}
在这种情况下,由于重新调整大小,我的图像大小和图像质量正在降低。有没有办法压缩图像质量而不重新调整尺寸?任何提示或解决方案?