Here you can find the source of imageToByte(BufferedImage img)
Parameter | Description |
---|---|
img | a parameter |
public static byte[] imageToByte(BufferedImage img)
//package com.java2s; //License from project: Open Source License import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { /**/*from w w w .j a va 2 s . c om*/ * Conversion d'image vers Byte * * @param img * @return */ public static byte[] imageToByte(BufferedImage img) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] bytes = null; try { ImageIO.write(img, "jpg", baos); baos.flush(); bytes = baos.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { try { baos.close(); } catch (IOException e) { e.printStackTrace(); } } return bytes; } }