我遇到了一些问题,无法压缩png
图像。
这是我用来压缩的代码
BufferedImage img = ImageIO.read(fileinput)
ByteArrayOutputStream baos = new ByteArrayOutputStream()
ImageOutputStream ios = ImageIO.createImageOutputStream(baos)
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg")
ImageWriter writer = iter.next()
ImageWriteParam iwp = writer.getDefaultWriteParam()
iwp.setCompressionMode(2)
iwp.setCompressionQuality(0.2)
writer.setOutput(ios)
writer.write(null, new IIOImage(img, null, null), iwp)
writer.dispose()
baos.flush()
FileOutputStream fos = new FileOutputStream(fileinput)
fos.write(baos.toByteArray())
fos.close()
但我不知道为什么我压缩png
文件..总是变成红色