Example usage for java.awt.image BufferedImage TYPE_INT_RGB

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

Introduction

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

Prototype

int TYPE_INT_RGB

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

Click Source Link

Document

Represents an image with 8-bit RGB color components packed into integer pixels.

Usage

From source file:com.aurel.track.attachment.AttachBL.java

private static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }//from w w w .  j  a  v  a  2 s  .co  m

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}

From source file:com.simiacryptus.mindseye.lang.Tensor.java

/**
 * To rgb png buffered png.//from w  ww  .ja  v a 2 s  .c om
 *
 * @param redBand   the red band
 * @param greenBand the green band
 * @param blueBand  the blue band
 * @return the buffered png
 */
@Nonnull
public BufferedImage toRgbImage(final int redBand, final int greenBand, final int blueBand) {
    assertAlive();
    @Nonnull
    final int[] dims = getDimensions();
    @Nonnull
    final BufferedImage img = new BufferedImage(dims[0], dims[1], BufferedImage.TYPE_INT_RGB);
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            if (getDimensions()[2] == 1) {
                final double value = this.get(x, y, 0);
                img.setRGB(x, y, Tensor.bound8bit((int) value) * 0x010101);
            } else {
                final double red = Tensor.bound8bit(this.get(x, y, redBand));
                final double green = Tensor.bound8bit(this.get(x, y, greenBand));
                final double blue = Tensor.bound8bit(this.get(x, y, blueBand));
                img.setRGB(x, y, (int) (red + ((int) green << 8) + ((int) blue << 16)));
            }
        }
    }
    return img;
}

From source file:com.att.aro.diagnostics.GraphPanel.java

/**
 * Returns buffered image of current viewport in provided JScrollPane.
 * //w  ww.  j  a va2 s . co  m
 * @param pane
 * @return Graph image.
 */
private BufferedImage createImage(JScrollPane pane) {
    JViewport jVPort = pane.getViewport();
    jVPort.getWidth();
    int w = jVPort.getWidth();
    int h = jVPort.getHeight();
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    jVPort.paint(g);
    return bi;
}

From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java

/**
 * Creates a buffered image from an image
 * @param image the image// www  .j  a va2s  .  co  m
 * @return the buffered image
 */
public static BufferedImage getBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}

From source file:com.googlecode.libautocaptcha.tools.VodafoneItalyTool.java

private java.awt.Image convertImage(net.sourceforge.javaocr.Image image) {
    final int W = image.getWidth();
    final int H = image.getHeight();
    BufferedImage result = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
    AwtImage temp = new AwtImage(result);
    image.copy(temp);// w w w .  j av a  2  s. c o  m
    result.setRGB(0, 0, W, H, temp.pixels, 0, W);
    return result;
}

From source file:net.frontlinesms.plugins.forms.FormsPluginController.java

private void convertByteImageToFile(byte[] imageByte, String path) throws Exception {
    System.out.println("path ...... convertByteImageToFile ......... " + path);

    ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
    Iterator<?> readers = ImageIO.getImageReadersByFormatName("jpg");

    ImageReader reader = (ImageReader) readers.next();
    Object source = bis;/*w w w .  j a v  a 2  s  .  c o  m*/
    ImageInputStream iis = ImageIO.createImageInputStream(source);
    reader.setInput(iis, true);
    ImageReadParam param = reader.getDefaultReadParam();

    Image image = reader.read(0, param);
    //got an image file

    BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    //bufferedImage is the RenderedImage to be written

    Graphics2D g2 = bufferedImage.createGraphics();
    g2.drawImage(image, null, null);

    File imageFile = new File(path);
    ImageIO.write(bufferedImage, "jpg", imageFile);
    System.out.println(" end write image ");
}

From source file:ded.ui.DiagramController.java

/** Get and log some details related to display scaling, particularly
  * to help diagnose the graphics bugs on HiDPI/Retina displays. */
public void logDisplayScaling() {
    // Based on code from
    // http://lubosplavucha.com/java/2013/09/02/retina-support-in-java-for-awt-swing/

    try {//from w w w  .  j  av a 2 s  . co  m
        // Dump a bunch of possibly interesting JVM properties.
        String propertyNames[] = { "awt.toolkit", "java.awt.graphicsenv", "java.runtime.name",
                "java.runtime.version", "java.vendor", "java.version", "java.vm.name", "java.vm.vendor",
                "java.vm.version", };
        for (String name : propertyNames) {
            this.log("property " + name + ": " + System.getProperty(name));
        }

        // Try a property specific to the Apple JVM.
        this.log("apple.awt.contentScaleFactor: "
                + Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor"));

        // Try something specific to OpenJDK.  Here, we
        // reflectively query some private field.  Yuck.
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        try {
            Field field = gd.getClass().getDeclaredField("scale");
            field.setAccessible(true);
            this.log("GraphicsEnvironment.scale: " + field.get(gd));
        } catch (NoSuchFieldException e) {
            this.log("GraphicsEnvironment does not have a 'scale' field");
        }

        // Check some details of "compatible" images.
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        BufferedImage bi = gc.createCompatibleImage(64, 64);
        ColorModel cm = bi.getColorModel();
        this.log("compatible image color model: " + cm);

        // Do the same for a specific imageType that seems to be
        // commonly used, and that I am using when saving to PNG.
        bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
        cm = bi.getColorModel();
        this.log("TYPE_INT_ARGB color model: " + cm);

        // And one more.
        bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
        cm = bi.getColorModel();
        this.log("TYPE_INT_RGB color model: " + cm);
    } catch (Exception e) {
        this.log("exception during logDisplayScaling(): " + Util.getExceptionMessage(e));
        this.logNoNewline(Util.getExceptionStackTrace(e));
    }
}

From source file:biogenesis.Organism.java

public BufferedImage getImage() {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    g.setBackground(Color.BLACK);
    g.clearRect(0, 0, width, height);/*from   ww w .  j a v  a  2s  .  co  m*/
    for (int i = _segments - 1; i >= 0; i--) {
        g.setColor(_segColor[i]);
        g.drawLine(x1[i] - x + _centerX, y1[i] - y + _centerY, x2[i] - x + _centerX, y2[i] - y + _centerY);
    }
    return image;
}

From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

/**
 * Write a blank image so user doesn't see the broken icon.
 *///from w  w w .  j  a va  2  s .com
private void writePlaceholderImage(OutputStream os) throws IOException {
    int placeholderSize = (int) (ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX * 0.75);
    BufferedImage buffer = new BufferedImage(placeholderSize, placeholderSize, BufferedImage.TYPE_INT_RGB);
    Graphics g = buffer.createGraphics();
    g.setColor(Color.lightGray);
    g.fillRect(0, 0, placeholderSize, placeholderSize);
    g.setColor(Color.black);
    g.drawString("Not available", placeholderSize / 4, placeholderSize / 4);
    ImageIO.write(buffer, "png", os);
}

From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

/**
 * Write a blank thumbnail image so user doesn't see the broken icon.
 *//*ww  w  .ja v  a 2  s. c om*/
private void writePlaceholderThumbnailImage(OutputStream os, int placeholderSize) throws IOException {
    // Make the image a bit bigger to account for the empty space around the generated image.
    // If we can find a way to remove this empty space, we don't need to make the chart bigger.
    BufferedImage buffer = new BufferedImage(placeholderSize + 16, placeholderSize + 9,
            BufferedImage.TYPE_INT_RGB);
    Graphics g = buffer.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, placeholderSize + 16, placeholderSize + 9);
    g.setColor(Color.gray);
    g.drawLine(8, placeholderSize + 5, placeholderSize + 8, placeholderSize + 5); // x-axis
    g.drawLine(8, 5, 8, placeholderSize + 5); // y-axis
    g.setColor(Color.black);
    Font font = g.getFont();
    g.setFont(new Font(font.getName(), font.getStyle(), 8));
    g.drawString("N/A", 9, placeholderSize);
    ImageIO.write(buffer, "png", os);
}