Example usage for java.awt.image BufferedImage TYPE_INT_BGR

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

Introduction

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

Prototype

int TYPE_INT_BGR

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

Click Source Link

Document

Represents an image with 8-bit RGB color components, corresponding to a Windows- or Solaris- style BGR color model, with the colors Blue, Green, and Red packed into integer pixels.

Usage

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

private void setImageDataFields(BufferedImage chip, ImageSegment chipImageSegment) throws IOException {

    int[] componentSizes = chip.getColorModel().getComponentSize();
    int pixelSize = chip.getColorModel().getPixelSize();

    switch (chip.getType()) {
    case BufferedImage.TYPE_BYTE_GRAY:
    case BufferedImage.TYPE_USHORT_GRAY:
    case BufferedImage.TYPE_BYTE_BINARY:
        setMonochrome(chipImageSegment, componentSizes[0], pixelSize);
        break;/*from   www.j a  v a 2s  .  c  o m*/
    case BufferedImage.TYPE_3BYTE_BGR:
    case BufferedImage.TYPE_INT_BGR:
        setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBTRUECOLOUR,
                componentSizes[0], pixelSize / 3, new String[] { "B", "G", "R" });
        break;
    case BufferedImage.TYPE_4BYTE_ABGR:
    case BufferedImage.TYPE_4BYTE_ABGR_PRE:
        setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBTRUECOLOUR,
                componentSizes[0], pixelSize / 4, new String[] { "B", "G", "R" });
        break;
    case BufferedImage.TYPE_INT_ARGB_PRE:
    case BufferedImage.TYPE_INT_ARGB:
        setARGB(chipImageSegment, componentSizes[0], pixelSize);
        break;
    case BufferedImage.TYPE_INT_RGB:
    case BufferedImage.TYPE_USHORT_555_RGB:
        setRGB(chipImageSegment, componentSizes[0], pixelSize);
        break;
    case BufferedImage.TYPE_CUSTOM:
        if (componentSizes.length == 1) {
            setMonochrome(chipImageSegment, componentSizes[0], pixelSize);
        } else if (componentSizes.length == 3) {
            setRGB(chipImageSegment, componentSizes[0], pixelSize);
        } else if (componentSizes.length == 4) {
            setARGB(chipImageSegment, componentSizes[0], pixelSize);
        } else {
            throw new IOException(
                    "unsupported color model for image type CUSTOM, only monochrome and 32-bit argb are supported");
        }
        break;
    case BufferedImage.TYPE_BYTE_INDEXED:
        setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBLUT,
                componentSizes[0], pixelSize, new String[] { "LU" });
        break;
    case BufferedImage.TYPE_USHORT_565_RGB:
        // don't know how to handle this one, since the bitsPerPixelPerBand is not consistent
        break;
    default:
        throw new IOException("unsupported image data type: type=" + chip.getType());
    }
}

From source file:net.rptools.maptool.util.PersistenceUtil.java

static public void saveCampaignThumbnail(String fileName) {
    BufferedImage screen = MapTool.takeMapScreenShot(new PlayerView(MapTool.getPlayer().getRole()));
    if (screen == null)
        return;/*from w ww. j  a  v a 2  s. c o m*/

    Dimension imgSize = new Dimension(screen.getWidth(null), screen.getHeight(null));
    SwingUtil.constrainTo(imgSize, 200, 200);

    BufferedImage thumb = new BufferedImage(imgSize.width, imgSize.height, BufferedImage.TYPE_INT_BGR);
    Graphics2D g2d = thumb.createGraphics();
    g2d.drawImage(screen, 0, 0, imgSize.width, imgSize.height, null);
    g2d.dispose();

    File thumbFile = getCampaignThumbnailFile(fileName);

    try {
        ImageIO.write(thumb, "jpg", thumbFile);
    } catch (IOException ioe) {
        MapTool.showError("msg.error.failedSaveCampaignPreview", ioe);
    }
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static RegularField bufferedImage2RegularField(BufferedImage inImage, boolean vFlip) {
    if (inImage == null) {
        return null;
    }/*  w  w  w  . java  2  s .  c o m*/

    int[] dims = new int[2];
    dims[0] = inImage.getWidth();
    dims[1] = inImage.getHeight();

    RegularField field = new RegularField(dims);

    WritableRaster raster = inImage.getRaster();
    byte[][] samples = null;
    int[][] samples32 = null;
    int i = 0;
    switch (inImage.getType()) {
    case BufferedImage.TYPE_BYTE_GRAY:
        samples = new byte[1][];
        samples[0] = new byte[dims[0] * dims[1]];
        if (vFlip) {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i++] = (byte) raster.getSample(x, dims[1] - y - 1, 0);
                }
            }
        } else {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i++] = (byte) raster.getSample(x, y, 0);
                }
            }
        }
        field.addData(DataArray.create(samples[0], 1, "grayscaleData"));
        break;
    case BufferedImage.TYPE_USHORT_GRAY:
        samples32 = new int[1][];
        samples32[0] = new int[dims[0] * dims[1]];
        if (vFlip) {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples32[0][i++] = (int) raster.getSample(x, dims[1] - y - 1, 0);
                }
            }
        } else {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples32[0][i++] = (int) raster.getSample(x, y, 0);
                }
            }
        }
        field.addData(DataArray.create(samples32[0], 1, "grayscaleData"));
        break;
    case BufferedImage.TYPE_INT_RGB:
        samples = new byte[3][];
        samples[0] = new byte[dims[0] * dims[1]];
        samples[1] = new byte[dims[0] * dims[1]];
        samples[2] = new byte[dims[0] * dims[1]];
        if (vFlip) {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i] = (byte) raster.getSample(x, dims[1] - y - 1, 0);
                    samples[1][i] = (byte) raster.getSample(x, dims[1] - y - 1, 1);
                    samples[2][i] = (byte) raster.getSample(x, dims[1] - y - 1, 2);
                    i++;
                }
            }
        } else {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i] = (byte) raster.getSample(x, y, 0);
                    samples[1][i] = (byte) raster.getSample(x, y, 1);
                    samples[2][i] = (byte) raster.getSample(x, y, 2);
                    i++;
                }
            }
        }
        field.addData(DataArray.create(samples[0], 1, "redData"));
        field.addData(DataArray.create(samples[1], 1, "greenData"));
        field.addData(DataArray.create(samples[2], 1, "blueData"));
        break;
    case BufferedImage.TYPE_3BYTE_BGR:
    case BufferedImage.TYPE_INT_BGR:
        samples = new byte[3][];
        samples[0] = new byte[dims[0] * dims[1]];
        samples[1] = new byte[dims[0] * dims[1]];
        samples[2] = new byte[dims[0] * dims[1]];
        if (vFlip) {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i] = (byte) raster.getSample(x, dims[1] - y - 1, 0);
                    samples[1][i] = (byte) raster.getSample(x, dims[1] - y - 1, 1);
                    samples[2][i] = (byte) raster.getSample(x, dims[1] - y - 1, 2);
                    i++;
                }
            }
        } else {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i] = (byte) raster.getSample(x, y, 0);
                    samples[1][i] = (byte) raster.getSample(x, y, 1);
                    samples[2][i] = (byte) raster.getSample(x, y, 2);
                    i++;
                }
            }
        }
        field.addData(DataArray.create(samples[0], 1, "blueData"));
        field.addData(DataArray.create(samples[1], 1, "greenData"));
        field.addData(DataArray.create(samples[2], 1, "redData"));
        break;
    case BufferedImage.TYPE_INT_ARGB:
        samples = new byte[4][];
        samples[0] = new byte[dims[0] * dims[1]];
        samples[1] = new byte[dims[0] * dims[1]];
        samples[2] = new byte[dims[0] * dims[1]];
        samples[3] = new byte[dims[0] * dims[1]];
        for (int y = 0; y < dims[1]; y++) {
            for (int x = 0; x < dims[0]; x++) {
                samples[0][i] = (byte) raster.getSample(x, dims[1] - y - 1, 0);
                samples[1][i] = (byte) raster.getSample(x, dims[1] - y - 1, 1);
                samples[2][i] = (byte) raster.getSample(x, dims[1] - y - 1, 2);
                samples[3][i] = (byte) raster.getSample(x, dims[1] - y - 1, 3);
                i++;
            }
        }
        field.addData(DataArray.create(samples[0], 1, "redData"));
        field.addData(DataArray.create(samples[1], 1, "greenData"));
        field.addData(DataArray.create(samples[2], 1, "blueData"));
        field.addData(DataArray.create(samples[3], 1, "alphaData"));
        break;
    case BufferedImage.TYPE_4BYTE_ABGR:
        samples = new byte[4][];
        samples[0] = new byte[dims[0] * dims[1]];
        samples[1] = new byte[dims[0] * dims[1]];
        samples[2] = new byte[dims[0] * dims[1]];
        samples[3] = new byte[dims[0] * dims[1]];
        for (int y = 0; y < dims[1]; y++) {
            for (int x = 0; x < dims[0]; x++) {
                samples[0][i] = (byte) raster.getSample(x, dims[1] - y - 1, 0);
                samples[1][i] = (byte) raster.getSample(x, dims[1] - y - 1, 1);
                samples[2][i] = (byte) raster.getSample(x, dims[1] - y - 1, 2);
                samples[3][i] = (byte) raster.getSample(x, dims[1] - y - 1, 3);
                i++;
            }
        }
        field.addData(DataArray.create(samples[0], 1, "alphaData"));
        field.addData(DataArray.create(samples[1], 1, "redData"));
        field.addData(DataArray.create(samples[2], 1, "greenData"));
        field.addData(DataArray.create(samples[3], 1, "blueData"));
        break;
    default:
        BufferedImage newImg = new BufferedImage(inImage.getWidth(), inImage.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = newImg.createGraphics();
        g2d.drawImage(inImage, null, 0, 0);
        g2d.dispose();
        raster = newImg.getRaster();
        samples = new byte[3][];
        samples[0] = new byte[dims[0] * dims[1]];
        samples[1] = new byte[dims[0] * dims[1]];
        samples[2] = new byte[dims[0] * dims[1]];
        if (vFlip) {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i] = (byte) raster.getSample(x, dims[1] - y - 1, 0);
                    samples[1][i] = (byte) raster.getSample(x, dims[1] - y - 1, 1);
                    samples[2][i] = (byte) raster.getSample(x, dims[1] - y - 1, 2);
                    i++;
                }
            }
        } else {
            for (int y = 0; y < dims[1]; y++) {
                for (int x = 0; x < dims[0]; x++) {
                    samples[0][i] = (byte) raster.getSample(x, y, 0);
                    samples[1][i] = (byte) raster.getSample(x, y, 1);
                    samples[2][i] = (byte) raster.getSample(x, y, 2);
                    i++;
                }
            }
        }
        field.addData(DataArray.create(samples[0], 1, "redData"));
        field.addData(DataArray.create(samples[1], 1, "greenData"));
        field.addData(DataArray.create(samples[2], 1, "blueData"));
    }

    float[][] affine = new float[4][3];
    for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
            affine[j][k] = 0.0f;
            if (j == k)
                affine[j][k] = 1.0f;
        }
    }

    affine[3][0] = -(float) dims[0] / 2.0f;
    affine[3][1] = -(float) dims[1] / 2.0f;
    affine[3][2] = 0.0f;
    field.setAffine(affine);
    return field;
}