Capture image as BYteBuffer.

@param webcam the webcam from which image should be obtained
@param format the file format
@return Byte buffer
433841
public static final ByteBuffer getImageByteBuffer(Webcam webcam, String format) {
		return ByteBuffer.wrap(getImageBytes(webcam, format));
	}
892996
public Webcam getWebcam(String name, Dimension dimension) {
        if (name == null) {
            return getWebcam(dimension);
        }

        Webcam webcam = webcams.get(name);
        openWebcam(webcam, dimension);
        return webcam;
    }
1186599
public static String format(ImageFormat format) {
    if (format == null) {
      throw new IllegalArgumentException("You must specify an image format.");
    }
    return FILTER_FORMAT + "(" + format.value + ")";
  }
81082
public byte[] export(final StateFormat format) {
    try {
      if (format == StateFormat.JSON) {
        return JACKSON.writeValueAsBytes(this);
      } else {
        throw new IllegalStateException("Unsupported Format " + format);
      }
    } catch (Exception ex) {
      throw new RuntimeException("Could not encode SessionState to Format " + format, ex);
    }
  }
286649
public static FileTransformer fileTransformer(Format format) {
        switch (format) {
            case MATLAB_SPARSE:
                return new MatlabSparseFileTransformer();
            case SVDLIBC_SPARSE_TEXT:
                return new SvdlibcSparseTextFileTransformer();
            case SVDLIBC_DENSE_TEXT:
                return new SvdlibcDenseTextFileTransformer();
            case SVDLIBC_SPARSE_BINARY:
                return new SvdlibcSparseBinaryFileTransformer();
            case SVDLIBC_DENSE_BINARY:
                return new SvdlibcDenseBinaryFileTransformer();
            default:
                throw new UnsupportedOperationException(
                        "Transforming format " + format + " is currently " +
                        "not implemented.  Please email " +
                        "s-space-research-dev@googlegroups.com to have this " +
                        "implemented.");
        }
    }
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;
    }
178161
public static byte[] toByteArray(Bitmap bitmap, Bitmap.CompressFormat format, int quality) {
        ByteArrayOutputStream out = null;
        try {
            out = new ByteArrayOutputStream();
            bitmap.compress(format, quality, out);
            return out.toByteArray();
        } finally {
            CloseableUtils.close(out);
        }
    }
696183
public synchronized byte[] getBuffer() {
        byte[] dest = new byte[buf.length];
        System.arraycopy(buf, 0, dest, 0, dest.length);
        return dest;
    }
26523
public static ByteBuffer toByteBuffer(String s) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(s.length());
        buffer.put(s.getBytes(UTF_8));
        buffer.flip();
        return buffer;
    }
1437
public BufferedImage getBufferedImage(int width, int height) {
        // using the new approach of Java 2D API
        BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = (Graphics2D) buf.getGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2d.drawImage(image, 0, 0, width, height, null);
        g2d.dispose();
        return (buf);
    }
645462
public static BufferedImage getImage(byte[] imageBytes) throws IOException {

		BufferedImage image = null;

		if (imageBytes != null) {
			ByteArrayInputStream stream = new ByteArrayInputStream(imageBytes);
			image = ImageIO.read(stream);
			stream.close();
		}

		return image;
	}
1321528
public void handleWebcam() {
		final Webcam webcam = openSelectedCamera();
		if( desiredWidth > 0 && desiredHeight > 0 )
			UtilWebcamCapture.adjustResolution(webcam, desiredWidth, desiredHeight);

		webcam.open();

		// close the webcam gracefully on exit
		Runtime.getRuntime().addShutdownHook(new Thread(){public void run(){
			if(webcam.isOpen()){System.out.println("Closing webcam");webcam.close();}}});

		ComputeGeometryScore quality = new ComputeGeometryScore(zeroSkew,detector.getLayout());
		AssistedCalibrationGui gui = new AssistedCalibrationGui(webcam.getViewSize());
		JFrame frame = ShowImages.showWindow(gui, "Webcam Calibration", true);

		GrayF32 gray = new GrayF32(webcam.getViewSize().width,webcam.getViewSize().height);

		if( desiredWidth > 0 && desiredHeight > 0 ) {
			if (gray.width != desiredWidth || gray.height != desiredHeight )
				System.err.println("Actual camera resolution does not match desired.  Actual: "+gray.width+" "+gray.height+
				"  Desired: "+desiredWidth+" "+desiredHeight);
		}

		AssistedCalibration assisted = new AssistedCalibration(detector,quality,gui,OUTPUT_DIRECTORY, IMAGE_DIRECTORY);
		assisted.init(gray.width,gray.height);

		BufferedImage image;
		while( (image = webcam.getImage()) != null && !assisted.isFinished()) {
			ConvertBufferedImage.convertFrom(image, gray);

			try {
				assisted.process(gray,image);
			} catch( RuntimeException e ) {
				System.err.println("BUG!!! saving image to crash_image.png");
				UtilImageIO.saveImage(image, "crash_image.png");
				throw e;
			}
		}
		webcam.close();
		if( assisted.isFinished() ) {
			frame.setVisible(false);

			inputDirectory = new File(OUTPUT_DIRECTORY, IMAGE_DIRECTORY).getPath();
			outputFileName = new File(OUTPUT_DIRECTORY, "intrinsic.yaml").getPath();
			handleDirectory();
		}
	}
684859
public function getImage(string $format = null) : string
    {
        if (!$format) {
            $format = explode('/', $this->info['mime'], 2)[1];
        }
        switch (strtolower($format)) {
            case 'jpg':
            case 'jpeg':
                ob_start();
                imagejpeg($this->data);
                return ob_get_clean();
            case 'bitmap':
            case 'bmp':
                ob_start();
                imagewbmp($this->data);
                return ob_get_clean();
            case 'png':
                ob_start();
                imagepng($this->data);
                return ob_get_clean();
            case 'gif':
                ob_start();
                imagegif($this->data);
                return ob_get_clean();
            case 'webp':
                ob_start();
                imagewebp($this->data, null);
                return ob_get_clean();
            default:
                throw new ImageException('Unsupported format');
        }
    }
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);
    }
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;
        }
    }
1143470
public static byte[] getBufferByteArray(BufferedImage image) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		try {
			ImageIO.write(image, "png", os);
		} catch (IOException e) {
			logger.error("getBufferByteArray error", e);
		}
		return os.toByteArray();
	}
907712
public static GifImage create(byte[] source) {
    ensure();
    Preconditions.checkNotNull(source);

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(source.length);
    byteBuffer.put(source);
    byteBuffer.rewind();

    return nativeCreateFromDirectByteBuffer(byteBuffer);
  }