Example usage for java.awt.image Raster createBandedRaster

List of usage examples for java.awt.image Raster createBandedRaster

Introduction

In this page you can find the example usage for java.awt.image Raster createBandedRaster.

Prototype

public static WritableRaster createBandedRaster(int dataType, int w, int h, int bands, Point location) 

Source Link

Document

Creates a Raster based on a BandedSampleModel with the specified data type, width, height, and number of bands.

Usage

From source file:nl.ru.ai.projects.parrot.tools.TwitterAccess.java

/**
 * Returns a RenderedImage object from a byte array
 * @param cameraOutput The camera output to transform into a RenderedImage
 * @return The RenderedImage that resulted from the camera output
 *//*www .  j a v  a 2 s.  c  o  m*/
private RenderedImage getImageFromCamera(byte[] cameraOutput) {
    BufferedImage image = new BufferedImage(VideoPollInterface.FRONT_VIDEO_FRAME_WIDTH,
            VideoPollInterface.FRONT_VIDEO_FRAME_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
    if (cameraOutput != null) {
        WritableRaster raster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE,
                VideoPollInterface.FRONT_VIDEO_FRAME_WIDTH, VideoPollInterface.FRONT_VIDEO_FRAME_HEIGHT, 3,
                new Point(0, 0));
        raster.setDataElements(0, 0, VideoPollInterface.FRONT_VIDEO_FRAME_WIDTH,
                VideoPollInterface.FRONT_VIDEO_FRAME_HEIGHT, cameraOutput);
        image.setData(raster);
    }

    return image;
}

From source file:org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.java

/**
 * Returns the content of the given image as an AWT buffered image with an RGB color space.
 * If a color key mask is provided then an ARGB image is returned instead.
 * This method never returns null./*from   w w w  .  j a v  a 2s .c  o m*/
 * @param pdImage the image to read
 * @param colorKey an optional color key mask
 * @return content of this image as an RGB buffered image
 * @throws IOException if the image cannot be read
 */
public static BufferedImage getRGBImage(PDImage pdImage, COSArray colorKey) throws IOException {
    if (pdImage.isEmpty()) {
        throw new IOException("Image stream is empty");
    }

    // get parameters, they must be valid or have been repaired
    final PDColorSpace colorSpace = pdImage.getColorSpace();
    final int numComponents = colorSpace.getNumberOfComponents();
    final int width = pdImage.getWidth();
    final int height = pdImage.getHeight();
    final int bitsPerComponent = pdImage.getBitsPerComponent();
    final float[] decode = getDecodeArray(pdImage);

    //
    // An AWT raster must use 8/16/32 bits per component. Images with < 8bpc
    // will be unpacked into a byte-backed raster. Images with 16bpc will be reduced
    // in depth to 8bpc as they will be drawn to TYPE_INT_RGB images anyway. All code
    // in PDColorSpace#toRGBImage expects and 8-bit range, i.e. 0-255.
    //
    WritableRaster raster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, width, height, numComponents,
            new Point(0, 0));

    // convert image, faster path for non-decoded, non-colormasked 8-bit images
    final float[] defaultDecode = pdImage.getColorSpace().getDefaultDecode(8);
    if (bitsPerComponent == 8 && Arrays.equals(decode, defaultDecode) && colorKey == null) {
        return from8bit(pdImage, raster);
    } else if (bitsPerComponent == 1 && colorKey == null) {
        return from1Bit(pdImage, raster);
    } else {
        return fromAny(pdImage, raster, colorKey);
    }
}