调整图像大小时颜色会丢失

时间:2012-06-14 21:04:59

标签: java image colors awt bufferedimage

我正在使用此方法更改图像大小:

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;
}

似乎图像失去色深。如何设置与源图像相同的颜色深度?

0 个答案:

没有答案