Example usage for java.nio IntBuffer get

List of usage examples for java.nio IntBuffer get

Introduction

In this page you can find the example usage for java.nio IntBuffer get.

Prototype

public IntBuffer get(int[] dest, int off, int len) 

Source Link

Document

Reads ints from the current position into the specified int array, starting from the specified offset, and increases the position by the number of ints read.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntBuffer bb = IntBuffer.allocate(10);
    bb.put(100);//  w  w  w  .ja v a 2s .co m

    bb.rewind();

    int[] intArray = new int[10];
    bb.get(intArray, 0, 2);

    System.out.println(Arrays.toString(intArray));

}

From source file:Main.java

static void toArray(IntBuffer src, int[] dst, int offset) {
    src.position(0);// w w w  . j  a va2  s  .c  om
    src.get(dst, offset, dst.length - offset);
}

From source file:org.opencastproject.composer.gstreamer.engine.GStreamerEncoderEngine.java

/**
 * Creates image out of gstreamer buffer. Buffer should have following properties: 32 bits/pixel and color depth of 24
 * bits. Output image format is chosen based on the output file name. If width or height are equal or less than 0,
 * original image size is retained./*  w w  w.  j  av  a2  s  .  c om*/
 * 
 * @param buffer
 *          gstreamer buffer from which image will be constructed
 * @param width
 *          width of the new image
 * @param height
 *          height of the new image
 * @param output
 *          output file name
 * @throws IOException
 *           if writing image fails
 */
private void createImageOutOfBuffer(Buffer buffer, int width, int height, String output) throws IOException {
    // get buffer information
    Structure structure = buffer.getCaps().getStructure(0);
    int origHeight = structure.getInteger("height");
    int origWidth = structure.getInteger("width");

    // create original image
    IntBuffer intBuf = buffer.getByteBuffer().asIntBuffer();
    int[] imageData = new int[intBuf.capacity()];
    intBuf.get(imageData, 0, imageData.length);
    BufferedImage originalImage = new BufferedImage(origWidth, origHeight, BufferedImage.TYPE_INT_RGB);
    originalImage.setRGB(0, 0, origWidth, origHeight, imageData, 0, origWidth);

    BufferedImage image;
    if (height <= 0 || width <= 0) {
        logger.info("Retaining image of original size {}x{}", origWidth, origHeight);
        image = originalImage;
    } else {
        logger.info("Resizing image from {}x{} to {}x{}",
                new Object[] { origWidth, origHeight, width, height });
        image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = image.createGraphics();
        graphics.setRenderingHints(imageRenderingHints);
        graphics.drawImage(originalImage, 0, 0, width, height, null);
        graphics.dispose();
    }

    // write image
    File outputFile = new File(output);
    ImageIO.write(image, FilenameUtils.getExtension(output), outputFile);
}