Saving BufferedImage using zip compression

SaTaN InSiDe

New Member
How would I go about saving a BufferedImage straight to a zip file.Here is my current code for saving my BufferedImage to a zip file but I do not know how to convert the BufferedImage to a InputStream so that it can be saved to the zip file.If possible I need to save the BufferedImage straight from RAM without saving it to HDD first\[code\]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();}\[/code\]
 
Top