我正在使用此方法更改图像大小:
private File resize(double scale, File file) throws IOException {
double scaledSize = targetSize * scale;
BufferedImage scaledImage = Scalr.resize(sourceImage, (int) scaledSize);
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(fileExt);
ImageWriter writer = iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1);
FileImageOutputStream output = new FileImageOutputStream(file);
writer.setOutput(output);
IIOImage image = new IIOImage(scaledImage, null, null);
writer.write(null, image, iwp);
writer.dispose();
return file;
}
似乎图像失去色深。如何设置与源图像相同的颜色深度?