List of utility methods to do Image to Byte Array
byte[] | bufferedImageToByte(BufferedImage image, String format) buffered Image To Byte final ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageIO.write(image, format, bos); return bos.toByteArray(); |
byte[] | bufferedImageToByte(BufferedImage originalImage) buffered Image To Byte ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, "jpg", baos); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close(); return imageInByte; |
byte[] | bufferedImageToByteArray(BufferedImage bufferedImage) Convert BufferedImage to byte array ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, IMAGE_FORMAT, baos); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close(); return imageInByte; |
ByteBuffer | bufferedImageToByteArray(BufferedImage image) buffered Image To Byte Array PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, true); pg.grabPixels(); int[] pixels = (int[]) pg.getPixels(); ByteBuffer out = ByteBuffer.allocate(pixels.length * 4); out.order(ByteOrder.nativeOrder()); for (int i = 0; i < pixels.length; i++) { out.putInt(pixels[i]); out.flip(); return out; |
byte[] | bufferedImageToByteArray(BufferedImage img) Converts a BufferedImage into a byte[]. ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(img, "JPEG", os); return os.toByteArray(); |
byte[] | bufferedImageToBytes(final BufferedImage bufferedImage, final ImageWriter imageWriter, final ImageWriteParam imageWriteParameter) Converts a BufferedImage into bytes using a specific image writer, and image write parameters if (bufferedImage == null) { throw new IllegalArgumentException("Buffered image may not be null"); if (imageWriter == null) { throw new IllegalArgumentException("Image writer may not be null"); try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream memoryCacheImage = new MemoryCacheImageOutputStream( ... |
byte[] | toByteArray(Image image) to Byte Array ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageIO.write(toBufferedImage(image), "jpg", bos); return bos.toByteArray(); |
byte[] | toByteArray(Image img) to Byte Array ImageIcon ii = new ImageIcon(img); img = ii.getImage(); BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.drawImage(img, 0, 0, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemoryCacheImageOutputStream mos = new MemoryCacheImageOutputStream(baos); Object[] obj = getWriter(1); ... |