Convert {@link BufferedImage} to byte array.

@param image the image to be converted
@param format the output image format
@return New array of bytes
421833
public static byte[] toByteArray(BufferedImage image, String format) {

		byte[] bytes = null;
		ByteArrayOutputStream baos = new ByteArrayOutputStream();

		try {
			ImageIO.write(image, format, baos);
			bytes = baos.toByteArray();
		} catch (IOException e) {
			throw new WebcamException(e);
		} finally {
			try {
				baos.close();
			} catch (IOException e) {
				throw new WebcamException(e);
			}
		}

		return bytes;
	}
1098382
private void writeImageDataHexEncoded(final OutputStream bab) throws IOException
    {
    	int cnt = 0;
    	for(int k = 0; k < imageData.length; k++) {
    		final byte[] chunk = imageData[k];
			for(int x = 0; x < chunk.length; x++) {
				bab.write(byte2charLUT, (chunk[x]&0xff)*2, 2);
				if(++cnt == 64) {
					bab.write('\n');
					cnt = 0;
				}
			}
		}    	
   		if(cnt > 0) bab.write('\n');
    }
367753
private BufferedImage buildImage(byte[] bgr) {
		BufferedImage image = new BufferedImage(resolution.width, resolution.height, BufferedImage.TYPE_3BYTE_BGR);
		byte[] imageData = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
		System.arraycopy(bgr, 0, imageData, 0, bgr.length);

		return image;
	}
393070
private void initPixelsArray(BufferedImage image) {
        int width = image.getWidth();
        int height = image.getHeight();
        pixels = new int[width * height];
        image.getRGB(0, 0, width, height, pixels, 0, width);

    }
337416
public BufferedImage createImage (int width, int height, int transparency)
    {
        return _icreator.createImage(width, height, transparency);
    }
759092
public static BufferedImage cloneImage( BufferedImage image ) {
		BufferedImage newImage = new BufferedImage( image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB );
		Graphics2D g = newImage.createGraphics();
		g.drawRenderedImage( image, null );
		g.dispose();
		return newImage;
	}
942142
public static ByteBuffer getImageByteBuffer(RenderedImage image) {
        ColorModel cm = image.getColorModel();
        WritableRaster wr = image.getData().createCompatibleWritableRaster(image.getWidth(), image.getHeight());
        image.copyData(wr);
        BufferedImage bi = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
        return convertImageData(bi);
    }
1164649
public static void saveImage(BufferedImage image, OutputStream output) throws IOException
    {
        ImageIO.write(image, "png", output);
    }
164942
public static String imgToBase64Str(BufferedImage image, String formatName) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        String base64Str = null;
        try {
            ImageIO.write(image, formatName == null ? "jpeg" : formatName, baos);
            byte[] bytes = baos.toByteArray();
            base64Str = CommonUtils.bytesToBase64Str(bytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            CommonUtils.closeIOStream(null, baos);
        }
        return base64Str;
    }
179206
@Override
	public void getImageBytes(ByteBuffer buffer) {
		final BufferedImage bi = getImage();
		if (bi != null) {
			buffer.put(ImageUtils.imageToBytes(bi));
		}
	}
1136858
public BufferedImage asBufferedImage(INDArray array, int dataType) {
        return converter2.convert(asFrame(array, dataType));
    }
1180694
public static byte[] toArray(ByteBuffer buffer) {
        if (buffer.hasArray()) {
            byte[] array = buffer.array();
            int from = buffer.arrayOffset() + buffer.position();
            return Arrays.copyOfRange(array, from, from + buffer.remaining());
        } else {
            byte[] to = new byte[buffer.remaining()];
            buffer.slice().get(to);
            return to;
        }
    }
1035898
public static BufferedImage copyImage(BufferedImage image)
    {
        final BufferedImage copy = createImage(image.getWidth(),
                                               image.getHeight(),
                                               image.getColorModel().getTransparency());
        final Graphics2D g = copy.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.drawImage(image, 0, 0, null);
        g.dispose();
        return copy;
    }
723715
public void setTileData(BufferedImage image, String imageFormat)
			throws IOException {
		byte[] bytes = ImageUtils.writeImageToBytes(image, imageFormat);
		setTileData(bytes);
	}
294729
public static BufferedImage toImage(String base64) throws IORuntimeException {
		byte[] decode = Base64.decode(base64, CharsetUtil.CHARSET_UTF_8);
		return toImage(decode);
	}
433841
public static final ByteBuffer getImageByteBuffer(Webcam webcam, String format) {
		return ByteBuffer.wrap(getImageBytes(webcam, format));
	}
112193
public static BufferedImage copy(BufferedImage image) {
        BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(),
            image.getType());
        return copy(image, newImage);
    }