Return image RGB data in form of {@link ByteBuffer}. Please note that {@link ByteBuffer}
returned by this method does not contain original JPEG data bytes, but bytes representing RGB
data of the image constructed from JPEG data.
962560
@Override
	public synchronized ByteBuffer getImageBytes() {
		final BufferedImage bi = getImage();
		if (bi == null) {
			return null;
		}
		return ByteBuffer.wrap(ImageUtils.imageToBytes(bi));
	}
1374340
public byte[] getBuffer() {
        if(buf == null)
            return null;
        if(offset == 0 && length == buf.length)
            return buf;
        else {
            byte[] retval=new byte[length];
            System.arraycopy(buf, offset, retval, 0, length);
            return retval;
        }
    }
354426
public static String getMimeType(byte[] bytes) {
        String suffix = getFileSuffix(bytes);
        String mimeType;

        if ("JPG".equals(suffix)) {
            mimeType = "image/jpeg";
        } else if ("GIF".equals(suffix)) {
            mimeType = "image/gif";
        } else if ("PNG".equals(suffix)) {
            mimeType = "image/png";
        } else if ("BMP".equals(suffix)) {
            mimeType = "image/bmp";
        } else {
            mimeType = "application/octet-stream";
        }

        return mimeType;
    }
269505
public byte[] encodeBytes(byte[] rgbValue)
        throws NoSuchAlgorithmException
    {
        rgbValue = this.encrypt(rgbValue);
        rgbValue = super.encodeBytes(rgbValue); // Base64 encoding
        return rgbValue;
    }
1297674
public static BufferedImage read (ByteBuffer byteBuffer)
        throws IOException
    {
        // read in our integer fields
        IntBuffer ibuf = byteBuffer.asIntBuffer();
        int width = ibuf.get();
        int height = ibuf.get();
        /* int tpixel = */ ibuf.get();
        int msize = ibuf.get();

        if (width > Short.MAX_VALUE || width < 0 || height > Short.MAX_VALUE || height < 0) {
            throw new IOException("Bogus image size " + width + "x" + height);
        }

        IndexColorModel cmodel;
        synchronized (_origin) { // any old object will do
            // make sure our colormap array is big enough
            if  (_cmap == null || _cmap.length < msize) {
                _cmap = new int[msize];
            }
            // read in the data and create our colormap
            ibuf.get(_cmap, 0, msize);
            cmodel = new IndexColorModel(
                8, msize, _cmap, 0, DataBuffer.TYPE_BYTE, null);
        }

        // advance the byte buffer accordingly
        byteBuffer.position(ibuf.position() * 4);

        // read in the image data itself
        byte[] data = new byte[width*height];
        byteBuffer.get(data);

        // create the image from our component parts
        DataBuffer dbuf = new DataBufferByte(data, data.length, 0);
        int[] offsets = new int[] { 0 };
        PixelInterleavedSampleModel smodel =
            new PixelInterleavedSampleModel(
                DataBuffer.TYPE_BYTE, width, height, 1, width, offsets);
        WritableRaster raster = WritableRaster.createWritableRaster(smodel, dbuf, _origin);
        return new BufferedImage(cmodel, raster, false, null);
    }
759960
protected static ByteBuffer getRgba(Image image) {
    int w = (int) image.width(), h = (int) image.height(), size = w * h;
    int[] rawPixels = new int[size];
    ByteBuffer pixels = ByteBuffer.allocateDirect(size * 4);
    pixels.order(ByteOrder.nativeOrder());
    IntBuffer rgba = pixels.asIntBuffer();
    image.getRgb(0, 0, w, h, rawPixels, 0, w);

    for (int i = 0; i < size; i++) {
      int argb = rawPixels[i];
      // Order is inverted because this is read as a byte array, and we store intel ints.
      rgba.put(i, ((argb >> 16) & 0x0ff) | (argb & 0x0ff00ff00) | ((argb & 0xff) << 16));
    }
    return pixels;
  }
378429
public static BufferedImage newBufferImage(int width, int height) {
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
		return image;
	}
1187940
public BufferedImage getSnapshot ()
    {
        BufferedImage baseSnap = _base.getSnapshot();
        BufferedImage img = new BufferedImage(_bounds.width, _bounds.height,
            baseSnap.getType());
        Graphics2D gfx = (Graphics2D) img.getGraphics();
        try {
            gfx.transform(_transform);
            gfx.drawImage(baseSnap, 0, 0, null);
        } finally {
            gfx.dispose();
        }
        return img;
    }
364719
public static Image getInstance(byte imgb[]) throws BadElementException,
			MalformedURLException, IOException {
		InputStream is = null;
		try {
			is = new java.io.ByteArrayInputStream(imgb);
			int c1 = is.read();
			int c2 = is.read();
			int c3 = is.read();
			int c4 = is.read();
			is.close();

			is = null;
			if (c1 == 'G' && c2 == 'I' && c3 == 'F') {
				GifImage gif = new GifImage(imgb);
				return gif.getImage(1);
			}
			if (c1 == 0xFF && c2 == 0xD8) {
				return new Jpeg(imgb);
			}
			if (c1 == 0x00 && c2 == 0x00 && c3 == 0x00 && c4 == 0x0c) {
				return new Jpeg2000(imgb);
			}
			if (c1 == 0xff && c2 == 0x4f && c3 == 0xff && c4 == 0x51) {
				return new Jpeg2000(imgb);
			}
			if (c1 == PngImage.PNGID[0] && c2 == PngImage.PNGID[1]
					&& c3 == PngImage.PNGID[2] && c4 == PngImage.PNGID[3]) {
				return PngImage.getImage(imgb);
			}
			if (c1 == 0xD7 && c2 == 0xCD) {
				return new ImgWMF(imgb);
			}
			if (c1 == 'B' && c2 == 'M') {
				return BmpImage.getImage(imgb);
			}
			if ((c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42)
					|| (c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0)) {
				RandomAccessFileOrArray ra = null;
				try {
					ra = new RandomAccessFileOrArray(imgb);
					Image img = TiffImage.getTiffImage(ra, 1);
                    if (img.getOriginalData() == null)
                        img.setOriginalData(imgb);
					return img;
				} finally {
					if (ra != null)
						ra.close();
				}

			}
			if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' ) {
				is = new java.io.ByteArrayInputStream(imgb);
				is.skip(4);
				int c5 = is.read();
				int c6 = is.read();
				int c7 = is.read();
				int c8 = is.read();
				if ( c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) {
					int file_header_flags = is.read();
					@SuppressWarnings("unused")
					int number_of_pages = -1;
					if ( (file_header_flags & 0x2) == 0x2 ) {
						number_of_pages = (is.read() << 24) | (is.read() << 16) | (is.read() << 8) | is.read();
					}
					is.close();
					// a jbig2 file with a file header.  the header is the only way we know here.                                                           
					// embedded jbig2s don't have a header, have to create them by explicit use of Jbig2Image?
					// nkerr, 2008-12-05  see also the getInstance(URL)
					RandomAccessFileOrArray ra = null;
					try {
						ra = new RandomAccessFileOrArray(imgb);
						Image img = JBIG2Image.getJbig2Image(ra, 1);
						if (img.getOriginalData() == null)
							img.setOriginalData(imgb);
						return img;
					} finally {
						if (ra != null)
							ra.close();
					}
				}
			}
			throw new IOException(
					"The byte array is not a recognized imageformat.");
		} finally {
			if (is != null) {
				is.close();
			}
		}
	}
1068711
def parse_buffer_to_png(data):
    

    images = []

    c1 = 0
    c2 = 0
    data_len = len(data)
    while c1 < data_len:
        # IEND can appear in a PNG without being the actual end
        if data[c2:c2 + 4] == b'IEND' and (c2 + 8 == data_len or data[c2+9:c2+12] == b'PNG'):
            images.append(Image.open(BytesIO(data[c1:c2 + 8])))
            c1 = c2 + 8
            c2 = c1
        c2 += 1

    return images
1233343
public static BufferedImage ByteBufferImage( byte[] data, int width, int height ) {
        int[] bandoffsets = {0, 1, 2, 3};
        DataBufferByte dbb = new DataBufferByte(data, data.length);
        WritableRaster wr = Raster.createInterleavedRaster(dbb, width, height, width * 4, 4, bandoffsets, null);
        int[] bitfield = {8, 8, 8, 8};

        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        ColorModel cm = new ComponentColorModel(cs, bitfield, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);

        return new BufferedImage(cm, wr, false, null);
    }
864266
public BufferedImage getBufferedImage(int width, int height) {
		BufferedImage bi = chart.createBufferedImage(width, height);
		return bi;
	}
239134
protected ByteBuffer inputStreamToByteBuffer() throws IOException {
        return byteBuffer == null ? byteBuffer = ByteBuffer.wrap(inputStreamToByteArray()) : byteBuffer;
    }
696183
public synchronized byte[] getBuffer() {
        byte[] dest = new byte[buf.length];
        System.arraycopy(buf, 0, dest, 0, dest.length);
        return dest;
    }
1111249
private static byte[] getByteArray(BufferedImage image) {
    checkNotNull(image);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
      ImageIO.write(image, "png", stream);
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }

    return stream.toByteArray();
  }
652331
public byte[] encodeBytes(byte[] rgbValue)
        throws NoSuchAlgorithmException
    {
        rgbValue = Base64.encodeSHA(rgbValue);
        rgbValue = super.encodeBytes(rgbValue); // Base64 encoding
        return rgbValue;
    }
1152311
public static BufferedImage convertToBufferedImage(Image img) {
        BufferedImage buff = createCompatibleTranslucentImage(
                img.getWidth(null), img.getHeight(null));
        Graphics2D g2 = buff.createGraphics();

        try {
            g2.drawImage(img, 0, 0, null);
        } finally {
            g2.dispose();
        }

        return buff;
    }