I am given a byte[] array in Java which contains the bytes for an image, and I need to output it into an image. How would I go about doing this?
Much thanks
You can simply iterate the byte array and print the byte using System. out. println() method.
Use the default CommonsMultipartFile where you to use the FileDiskItem object to create it. Example: FileItem fileItem = new DiskFileItem("fileData", "application/pdf",true, outputFile. getName(), 100000000, new java.
BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
If you know the type of image and only want to generate a file, there's no need to get a BufferedImage instance. Just write the bytes to a file with the correct extension.
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(path))) { out.write(bytes); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With