Example usage for java.awt.image BufferedImage TYPE_3BYTE_BGR

List of usage examples for java.awt.image BufferedImage TYPE_3BYTE_BGR

Introduction

In this page you can find the example usage for java.awt.image BufferedImage TYPE_3BYTE_BGR.

Prototype

int TYPE_3BYTE_BGR

To view the source code for java.awt.image BufferedImage TYPE_3BYTE_BGR.

Click Source Link

Document

Represents an image with 8-bit RGB color components, corresponding to a Windows-style BGR color model) with the colors Blue, Green, and Red stored in 3 bytes.

Usage

From source file:org.codice.alliance.imaging.chip.transformer.CatalogOutputAdapter.java

/**
 * @param image the BufferedImage to be converted.
 * @return a BinaryContent object containing the image data.
 * @throws IOException when the BufferedImage can't be written to temporary in-memory space.
 * @throws MimeTypeParseException thrown if the mime type is invalid
 *//*from ww  w .  ja v  a  2s .c  o  m*/
@SuppressWarnings("WeakerAccess")
public BinaryContent getBinaryContent(BufferedImage image) throws IOException, MimeTypeParseException {
    validateArgument(image, "image");

    BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_3BYTE_BGR);

    Graphics2D graphics = rgbImage.createGraphics();

    graphics.drawImage(image, 0, 0, null);

    InputStream fis = new ByteArrayInputStream(createJpg(rgbImage));
    return new BinaryContentImpl(fis, new MimeType(IMAGE_JPG));
}

From source file:SwingTest.java

/**
 * Initialize an offscreen Canvas3D.//from ww w  . j av  a  2  s . c  om
 */
protected Canvas3D createOffscreenCanvas3D() {
    offScreenCanvas3D = createCanvas3D(true);
    offScreenCanvas3D.getScreen3D().setSize(offScreenWidth, offScreenHeight);
    offScreenCanvas3D.getScreen3D().setPhysicalScreenHeight(0.0254 / 90 * offScreenHeight);
    offScreenCanvas3D.getScreen3D().setPhysicalScreenWidth(0.0254 / 90 * offScreenWidth);

    RenderedImage renderedImage = new BufferedImage(offScreenWidth, offScreenHeight,
            BufferedImage.TYPE_3BYTE_BGR);
    imageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGB8, renderedImage);
    imageComponent.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
    offScreenCanvas3D.setOffScreenBuffer(imageComponent);

    return offScreenCanvas3D;
}

From source file:com.xuggle.xuggler.UtilsTest.java

@SuppressWarnings("deprecation")
@Test/*ww w.  j  av  a 2s.  c o  m*/
public void testImageToImageRandomColor() {
    int w = 50;
    int h = 50;
    Random rnd = new Random();

    // construct an image of random colors

    BufferedImage image1 = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
    for (int x = 0; x < w; ++x)
        for (int y = 0; y < h; ++y) {
            Color c = new Color(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255));
            image1.setRGB(x, y, c.getRGB());
        }

    // convert image1 to a picture and then back to image2

    BufferedImage image2 = Utils.videoPictureToImage(Utils.imageToVideoPicture(image1, 0));

    // test that all the pixels in image2 are the same as image1

    for (int x = 0; x < w; ++x)
        for (int y = 0; y < h; ++y) {
            int pixel1 = image1.getRGB(x, y);
            int pixel2 = image2.getRGB(x, y);
            assertTrue("color value missmatch", pixel1 == pixel2);
        }
}

From source file:com.xuggle.xuggler.UtilsTest.java

@SuppressWarnings("deprecation")
@Test/*ww  w  .  j av  a 2 s .  c  o m*/
public void testPictureToPictureWithRotate() {
    // note that the image is square in this test to make rotation
    // easier to handle

    int size = 50;
    int black = Color.BLACK.getRGB();
    int white = Color.WHITE.getRGB();

    // construct an image with black and white stripped columns

    BufferedImage image1 = new BufferedImage(size, size, BufferedImage.TYPE_3BYTE_BGR);
    for (int x = 0; x < size; ++x)
        for (int y = 0; y < size; ++y) {
            int color = x % 2 == 0 ? black : white;
            image1.setRGB(x, y, color);
        }

    // convert image1 to a picture and then back to image2

    BufferedImage image2 = Utils.videoPictureToImage(Utils.imageToVideoPicture(image1, 0));

    // rotae image2

    AffineTransform t = AffineTransform.getRotateInstance(Math.PI / 2, image2.getWidth() / 2,
            image2.getHeight() / 2);
    AffineTransformOp ato = new AffineTransformOp(t, AffineTransformOp.TYPE_BICUBIC);
    BufferedImage image3 = new BufferedImage(size, size, BufferedImage.TYPE_3BYTE_BGR);
    ato.filter(image2, image3);

    // convert image2 to a picture and then back to image3

    BufferedImage image4 = Utils.videoPictureToImage(Utils.imageToVideoPicture(image3, 0));

    // test that image4 now contains stripped rows (not columns)

    for (int x = 0; x < size; ++x)
        for (int y = 0; y < size; ++y) {
            int pixel = image4.getRGB(x, y);
            int color = y % 2 == 0 ? black : white;
            assertTrue("color value missmatch", pixel == color);
        }
}

From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactory.java

private static BufferedImage getColorImage(BufferedImage image) {
    if (!image.getColorModel().hasAlpha()) {
        return image;
    }//w  w w .j a  v a 2s. co  m

    if (image.getColorModel().getColorSpace().getType() != ColorSpace.TYPE_RGB) {
        throw new UnsupportedOperationException("only RGB color spaces are implemented");
    }

    // create an RGB image without alpha
    // BEWARE: the previous solution in the history
    // g.setComposite(AlphaComposite.Src) and g.drawImage()
    // didn't work properly for TYPE_4BYTE_ABGR.
    // alpha values of 0 result in a black dest pixel!!!
    BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_3BYTE_BGR);
    return new ColorConvertOp(null).filter(image, rgbImage);
}

From source file:org.hydroponics.dao.JDBCHydroponicsDaoImpl.java

public byte[] getThumbnail(BufferedImage buffImage) throws IOException {
    BufferedImage pDestImage = new BufferedImage(Constants.THUMBNAIL_WIDTH, Constants.THUMBNAIL_HEIGHT,
            BufferedImage.TYPE_3BYTE_BGR);

    AffineTransform transform = new AffineTransform();
    transform.scale((float) Constants.THUMBNAIL_WIDTH / (float) buffImage.getWidth(),
            (float) Constants.THUMBNAIL_HEIGHT / (float) buffImage.getHeight());

    Graphics2D g = (Graphics2D) pDestImage.getGraphics();

    //set the rendering hints for a good thumbnail image
    Map m = g.getRenderingHints();
    m.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    m.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    m.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    m.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHints(m);//from w w w  . j  av  a 2 s  . c  o  m

    g.drawImage(buffImage, transform, null);
    g.dispose();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ImageIO.write(pDestImage, "JPEG", out);
    return out.toByteArray();
}

From source file:com.kabone.research.common.utils.FileUtil.java

public static boolean thumbnail(int imageWidth, int imageHeight, File originFileName, File thumbFileName) {
    boolean result = false;
    try {//from w  w  w.  j a  v  a  2s  . c  o  m
        BufferedImage bufferOriginImg = ImageIO.read(originFileName);
        BufferedImage bufferThumbImg = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR);
        Graphics2D graphic = bufferThumbImg.createGraphics();
        graphic.drawImage(bufferOriginImg, 0, 0, imageWidth, imageHeight, null);
        ImageIO.write(bufferThumbImg, "jpg", thumbFileName);
        result = true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

From source file:AnimatedGifEncoder.java

/**
 * Extracts image pixels into byte array "pixels"
 *//*  w w  w.j  av  a 2s . c o  m*/
protected void getImagePixels() {
    int w = image.getWidth();
    int h = image.getHeight();
    int type = image.getType();
    if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) {
        // create new image with right size/format
        BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        Graphics2D g = temp.createGraphics();
        g.drawImage(image, 0, 0, null);
        image = temp;
    }
    pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
}

From source file:org.codice.alliance.plugin.nitf.NitfPostIngestPlugin.java

private byte[] scaleImage(final BufferedImage bufferedImage, int width, int height) throws IOException {
    BufferedImage thumbnail = Thumbnails.of(bufferedImage).size(width, height).outputFormat(JPG)
            .imageType(BufferedImage.TYPE_3BYTE_BGR).asBufferedImage();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ImageIO.write(thumbnail, JPG, outputStream);
    outputStream.flush();/*  ww  w. j a va2s .com*/
    byte[] thumbnailBytes = outputStream.toByteArray();
    outputStream.close();
    return thumbnailBytes;
}

From source file:org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderImageIO.java

private BufferedImage getFallbackBufferedImage(ImageReader reader, int pageIndex, ImageReadParam param)
        throws IOException {
    //Work-around found at: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4799903
    //There are some additional ideas there if someone wants to go further.

    // Try reading a Raster (no color conversion).
    Raster raster = reader.readRaster(pageIndex, param);

    // Arbitrarily select a BufferedImage type.
    int imageType;
    switch (raster.getNumBands()) {
    case 1://from  www.j  a v a 2 s .c  o  m
        imageType = BufferedImage.TYPE_BYTE_GRAY;
        break;
    case 3:
        imageType = BufferedImage.TYPE_3BYTE_BGR;
        break;
    case 4:
        imageType = BufferedImage.TYPE_4BYTE_ABGR;
        break;
    default:
        throw new UnsupportedOperationException();
    }

    // Create a BufferedImage.
    BufferedImage bi = new BufferedImage(raster.getWidth(), raster.getHeight(), imageType);

    // Set the image data.
    bi.getRaster().setRect(raster);
    return bi;
}