BufferedImage を直接 zip ファイルに保存するにはどうすればよいですか。
BufferedImage を zip ファイルに保存するための現在のコードを次に示しますが、BufferedImage を InputStream に変換して zip ファイルに保存できるようにする方法がわかりません。
可能であれば、BufferedImage を最初に HDD に保存せずに RAM から直接保存する必要があります
byte[] buffer = new byte[1024];
try
{
FileOutputStream outputStream = new FileOutputStream(PathName + imageData.getFileNumber() + ".zip");
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
ZipEntry imageZipOutput = new ZipEntry(imageData.getFileNumber() + ".png");
zipOutputStream.putNextEntry(imageZipOutput);
//the BufferedImage is stored in imageData.getImage();
//how would I parse the BufferedImage to the InputStream below without saving the png first but straight from RAM
InputStream in = new InputStream();
int len;
while ((len = in.read(buffer)) > 0)
{
zipOutputStream.write(buffer, 0, len);
}
in.close();
zipOutputStream.closeEntry();
zipOutputStream.close();
}