Search in sources :

Example 41 with PixelGrabber

use of java.awt.image.PixelGrabber in project BombusMod by BombusMod.

the class J2SEMutableImage method getData.

public int[] getData() {
    if (grabber == null) {
        pixels = new int[getWidth() * getHeight()];
        grabber = new PixelGrabber(graphicsSurface.getImage(), 0, 0, getWidth(), getHeight(), pixels, 0, getWidth());
    }
    try {
        grabber.grabPixels();
    } catch (InterruptedException e) {
        logger.error("AWT exception", e);
    }
    return pixels;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 42 with PixelGrabber

use of java.awt.image.PixelGrabber in project vcell by virtualcell.

the class NativeImage method createPixels.

/**
 * This method was created in VisualAge.
 * @return byte[]
 */
private void createPixels() throws Exception {
    if (bPixelsExist()) {
        return;
    }
    PixelGrabber pg = new PixelGrabber(getJavaImage(), 0, 0, getSize().getX(), getSize().getX(), false);
    if (!pg.grabPixels()) {
        throw new Exception("Error getting pixels, status = " + pg.getStatus());
    }
    Object pixels = pg.getPixels();
    ColorModel colorModel = null;
    while (colorModel == null) {
        colorModel = pg.getColorModel();
    }
    if ((pixels instanceof int[]) && (colorModel instanceof DirectColorModel)) {
        newRGBAPixels = (int[]) pixels;
    } else if ((pixels instanceof byte[]) && (colorModel instanceof IndexColorModel)) {
        newIndexPixels = (byte[]) pixels;
        IndexColorModel indexColorModel = (IndexColorModel) colorModel;
        int colorMapSize = indexColorModel.getMapSize();
        byte[] temp_colorMap = new byte[colorMapSize * IndexColorMap.RGB_PACK_SIZE];
        byte[] reds = new byte[colorMapSize];
        indexColorModel.getReds(reds);
        byte[] greens = new byte[colorMapSize];
        indexColorModel.getGreens(greens);
        byte[] blues = new byte[colorMapSize];
        indexColorModel.getBlues(blues);
        for (int c = 0; c < colorMapSize; c += 1) {
            // make packed R,G,B array for ColorIndexModel
            int packCount = c * IndexColorMap.RGB_PACK_SIZE;
            temp_colorMap[packCount] = reds[c];
            temp_colorMap[packCount + 1] = greens[c];
            temp_colorMap[packCount + 2] = blues[c];
        }
        colorMap = new IndexColorMap(temp_colorMap);
    } else {
        throw new Exception("Unknown combination of data type=" + pixels.getClass().toString() + " and ColorModel=" + colorModel.getClass().toString());
    }
}
Also used : ColorModel(java.awt.image.ColorModel) DirectColorModel(java.awt.image.DirectColorModel) IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) PixelGrabber(java.awt.image.PixelGrabber) IOException(java.io.IOException) IndexColorModel(java.awt.image.IndexColorModel)

Example 43 with PixelGrabber

use of java.awt.image.PixelGrabber in project hale by halestudio.

the class ImageMarker method hasAlpha.

/**
 * Determines if an image has transparent pixels
 *
 * @param image the {@link Image}
 * @return if the given image has transparent pixels
 */
public static boolean hasAlpha(Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().hasAlpha();
    }
    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    // ignore
    }
    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}
Also used : ColorModel(java.awt.image.ColorModel) PixelGrabber(java.awt.image.PixelGrabber) BufferedImage(java.awt.image.BufferedImage)

Example 44 with PixelGrabber

use of java.awt.image.PixelGrabber in project gephi by gephi.

the class UIUtils method getGTKProfilerResultsBackground.

private static Color getGTKProfilerResultsBackground() {
    int[] pixels = new int[1];
    pixels[0] = -1;
    // Prepare textarea to grab the color from
    JTextArea textArea = new JTextArea();
    textArea.setSize(new Dimension(10, 10));
    textArea.doLayout();
    // Print the textarea to an image
    Image image = new BufferedImage(textArea.getSize().width, textArea.getSize().height, BufferedImage.TYPE_INT_RGB);
    textArea.printAll(image.getGraphics());
    // Grab appropriate pixels to get the color
    PixelGrabber pixelGrabber = new PixelGrabber(image, 5, 5, 1, 1, pixels, 0, 1);
    try {
        pixelGrabber.grabPixels();
        if (pixels[0] == -1) {
            // System background not customized
            return Color.WHITE;
        }
    } catch (InterruptedException e) {
        return getNonGTKProfilerResultsBackground();
    }
    return pixels[0] != -1 ? new Color(pixels[0]) : getNonGTKProfilerResultsBackground();
}
Also used : JTextArea(javax.swing.JTextArea) Color(java.awt.Color) PixelGrabber(java.awt.image.PixelGrabber) Dimension(java.awt.Dimension) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Example 45 with PixelGrabber

use of java.awt.image.PixelGrabber in project gephi by gephi.

the class JImagePanel method setPreferredBackground.

protected void setPreferredBackground() {
    int[] pixels = new int[1];
    PixelGrabber pg = null;
    switch(imageAlign) {
        case (SwingConstants.TOP):
            pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1);
            break;
        case (SwingConstants.BOTTOM):
            pg = new PixelGrabber(image, 0, 0, 1, 1, pixels, 0, 1);
            break;
        default:
            pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1);
    }
    try {
        if ((pg != null) && pg.grabPixels()) {
            setBackground(new Color(pixels[0]));
        }
    } catch (InterruptedException e) {
    }
}
Also used : Color(java.awt.Color) PixelGrabber(java.awt.image.PixelGrabber)

Aggregations

PixelGrabber (java.awt.image.PixelGrabber)82 BufferedImage (java.awt.image.BufferedImage)34 ColorModel (java.awt.image.ColorModel)17 IOException (java.io.IOException)16 Image (java.awt.Image)11 Color (java.awt.Color)9 DirectColorModel (java.awt.image.DirectColorModel)6 Point2D (java.awt.geom.Point2D)5 MemoryImageSource (java.awt.image.MemoryImageSource)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 ObfuscatedName (net.runelite.mapping.ObfuscatedName)5 ObfuscatedSignature (net.runelite.mapping.ObfuscatedSignature)5 Graphics2D (java.awt.Graphics2D)3 MediaTracker (java.awt.MediaTracker)3 ByteProcessor (ij.process.ByteProcessor)2 AWTException (java.awt.AWTException)2 Graphics (java.awt.Graphics)2 IndexColorModel (java.awt.image.IndexColorModel)2 URL (java.net.URL)2