Search in sources :

Example 21 with PixelGrabber

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

the class ImageConverter method getPixels.

public static int[] getPixels(BufferedImage image) {
    int iWidth = image.getWidth();
    int iHeight = image.getHeight();
    int numPixels = iWidth * iHeight;
    int[] rawPixels = new int[numPixels];
    if (rawPixels == null)
        return null;
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, iWidth, iHeight, rawPixels, 0, iWidth);
    try {
        grabber.grabPixels();
    } catch (InterruptedException e) {
    // do nothing
    }
    return rawPixels;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 22 with PixelGrabber

use of java.awt.image.PixelGrabber in project astroimagej by keastrid.

the class ImagePlus method getPixel.

/**
 *	Returns the pixel value at (x,y) as a 4 element array. Grayscale values
 *	are retuned in the first element. RGB values are returned in the first
 *	3 elements. For indexed color images, the RGB values are returned in the
 *	first 3 three elements and the index (0-255) is returned in the last.
 */
public int[] getPixel(int x, int y) {
    pvalue[0] = pvalue[1] = pvalue[2] = pvalue[3] = 0;
    switch(imageType) {
        case GRAY8:
        case COLOR_256:
            int index;
            if (ip != null)
                index = ip.getPixel(x, y);
            else {
                byte[] pixels8;
                if (img == null)
                    return pvalue;
                PixelGrabber pg = new PixelGrabber(img, x, y, 1, 1, false);
                try {
                    pg.grabPixels();
                } catch (InterruptedException e) {
                    return pvalue;
                }
                ;
                pixels8 = (byte[]) (pg.getPixels());
                index = pixels8 != null ? pixels8[0] & 0xff : 0;
            }
            if (imageType != COLOR_256) {
                pvalue[0] = index;
                return pvalue;
            }
            pvalue[3] = index;
        // fall through to get rgb values
        case COLOR_RGB:
            if (ip != null && ip.getNChannels() == 1) {
                pvalue[0] = ip.getPixel(x, y);
                return pvalue;
            }
            int c = 0;
            if (imageType == COLOR_RGB && ip != null)
                c = ip.getPixel(x, y);
            else {
                int[] pixels32 = new int[1];
                if (img == null)
                    return pvalue;
                PixelGrabber pg = new PixelGrabber(img, x, y, 1, 1, pixels32, 0, width);
                try {
                    pg.grabPixels();
                } catch (InterruptedException e) {
                    return pvalue;
                }
                ;
                c = pixels32[0];
            }
            int r = (c & 0xff0000) >> 16;
            int g = (c & 0xff00) >> 8;
            int b = c & 0xff;
            pvalue[0] = r;
            pvalue[1] = g;
            pvalue[2] = b;
            break;
        case GRAY16:
        case GRAY32:
            if (ip != null)
                pvalue[0] = ip.getPixel(x, y);
            break;
    }
    return pvalue;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 23 with PixelGrabber

use of java.awt.image.PixelGrabber in project astroimagej by keastrid.

the class AstroStackWindow method hasAlpha.

// This method returns true if the specified 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) {
    }
    // 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 24 with PixelGrabber

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

the class InputImage method hasAlpha.

private static boolean hasAlpha(Image image) {
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().hasAlpha();
    }
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    }
    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 25 with PixelGrabber

use of java.awt.image.PixelGrabber in project visualvm by oracle.

the class ImagePanel 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)86 BufferedImage (java.awt.image.BufferedImage)35 ColorModel (java.awt.image.ColorModel)18 IOException (java.io.IOException)18 Image (java.awt.Image)12 Color (java.awt.Color)9 DirectColorModel (java.awt.image.DirectColorModel)7 MemoryImageSource (java.awt.image.MemoryImageSource)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Point2D (java.awt.geom.Point2D)5 ByteArrayInputStream (java.io.ByteArrayInputStream)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 Dimension (java.awt.Dimension)2 Point (java.awt.Point)2 IndexColorModel (java.awt.image.IndexColorModel)2