Search in sources :

Example 1 with PixelGrabber

use of java.awt.image.PixelGrabber in project entando-core by entando.

the class PNGImageResizer method hasAlpha.

protected boolean hasAlpha(Image image) throws ApsSystemException {
    // 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) {
        throw new ApsSystemException("Error grabbing a single pixel", 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) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BufferedImage(java.awt.image.BufferedImage)

Example 2 with PixelGrabber

use of java.awt.image.PixelGrabber in project Lucee by lucee.

the class Image method hasAlpha.

/**
 * This method returns true if the specified image has transparent pixels
 * @param image
 * @return
 */
public static boolean hasAlpha(java.awt.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 : IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) PackedColorModel(java.awt.image.PackedColorModel) ColorModel(java.awt.image.ColorModel) PixelGrabber(java.awt.image.PixelGrabber) BufferedImage(java.awt.image.BufferedImage)

Example 3 with PixelGrabber

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

the class TextImage method refreshVerticalImage.

/**
 * This method was created by a SmartGuide.
 * @param g java.awt.Graphics
 */
private void refreshVerticalImage(Component component) {
    refreshImage(component);
    if (verticalImage != null) {
        return;
    }
    // 
    // copy image from horizontal image (image) to vertical image (verticalImage) (rotate 90 degrees)
    // 
    int[] pixels = new int[width * height];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new RuntimeException("interrupted waiting for pixels!");
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        throw new RuntimeException("image fetch aborted or errored");
    }
    int[] transposedPixels = new int[width * height];
    int transposed_i = 0;
    int transposed_j = 0;
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            transposed_i = j;
            transposed_j = width - 1 - i;
            int newPixel = pixels[j * width + i];
            // 
            if (newPixel != Color.black.getRGB()) {
                newPixel = 0x00000000;
            }
            // pixels[j * width + i];
            transposedPixels[transposed_i + transposed_j * height] = newPixel;
        }
    }
    java.awt.image.MemoryImageSource memoryImageSource = new java.awt.image.MemoryImageSource(height, width, transposedPixels, 0, height);
    Image tempImage = component.createImage(memoryImageSource);
    int verticalWidth = -1;
    int verticalHeight = -1;
    while (verticalWidth == -1 || verticalHeight == -1) {
        verticalWidth = tempImage.getWidth(component);
        verticalHeight = tempImage.getHeight(component);
    }
    verticalImage = tempImage;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber) Image(java.awt.Image)

Example 4 with PixelGrabber

use of java.awt.image.PixelGrabber in project mlib by myshzzx.

the class JavaSIFT method convert.

private FloatArray2D convert(java.awt.Image img) {
    FloatArray2D image;
    PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, true);
    try {
        grabber.grabPixels();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    int[] data = (int[]) grabber.getPixels();
    image = new FloatArray2D(grabber.getWidth(), grabber.getHeight());
    for (int d = 0; d < data.length; d++) image.data[d] = normTo1(RGB2Grey(data[d]));
    return image;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 5 with PixelGrabber

use of java.awt.image.PixelGrabber in project mlib by myshzzx.

the class FeatureCache method getImageData.

private int[] getImageData(Image img) {
    PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, true);
    try {
        grabber.grabPixels();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    int[] data = (int[]) grabber.getPixels();
    return data;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Aggregations

PixelGrabber (java.awt.image.PixelGrabber)35 BufferedImage (java.awt.image.BufferedImage)15 ColorModel (java.awt.image.ColorModel)7 Image (java.awt.Image)6 IOException (java.io.IOException)6 Point2D (java.awt.geom.Point2D)5 MemoryImageSource (java.awt.image.MemoryImageSource)4 Color (java.awt.Color)3 ByteProcessor (ij.process.ByteProcessor)2 MediaTracker (java.awt.MediaTracker)2 DirectColorModel (java.awt.image.DirectColorModel)2 IndexColorModel (java.awt.image.IndexColorModel)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Pair (mpicbg.trakem2.util.Pair)2 ObfuscatedName (net.runelite.mapping.ObfuscatedName)2 ObfuscatedSignature (net.runelite.mapping.ObfuscatedSignature)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 FloatProcessor (ij.process.FloatProcessor)1 AWTException (java.awt.AWTException)1