png ファイルの読み書きで問題が発生しました。ImageIO でバイト配列に読み取り、ImageIO を使用してこのバイト配列を再度書き込みます。ただし、ファイルサイズは大幅に増加します。これはどのように起こりますか?
public BufferedImage toBufferedImage(InputStream inputstream) {
try {
return ImageIO.read(inputstream);
} catch (Exception e) {
throw new IllegalStateException("Can't convert to buffered image", e);
}
}
public byte[] toByteArray(BufferedImage bufferedImage, String filetype) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
ImageIO.write(bufferedImage, filetype, output);
return output.toByteArray();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
フォローアップ: Java で記述され、ネイティブ コードを必要としない圧縮 PNG をサポートするライブラリはありますか?