Search in sources :

Example 56 with PixelGrabber

use of java.awt.image.PixelGrabber in project narchy by automenta.

the class ClipBMP method convertImage.

/*
	 * convertImage converts the memory image to the bitmap format (BRG). It
	 * also computes some information for the bitmap info header.
	 * 
	 */
private boolean convertImage(Image parImage, int parWidth, int parHeight) {
    int pad;
    bitmap = new int[parWidth * parHeight];
    PixelGrabber pg = new PixelGrabber(parImage, 0, 0, parWidth, parHeight, bitmap, 0, parWidth);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        e.printStackTrace();
        return (false);
    }
    pad = (4 - ((parWidth * 3) % 4)) * parHeight;
    biSizeImage = ((parWidth * parHeight) * 3) + pad;
    bfSize = biSizeImage + BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
    biWidth = parWidth;
    biHeight = parHeight;
    return (true);
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 57 with PixelGrabber

use of java.awt.image.PixelGrabber in project narchy by automenta.

the class Texture method drawImage.

/**
 * Draw an image
 *
 * @param x
 *           X
 * @param y
 *           Y
 * @param image
 *           Image to draw
 */
public void drawImage(final int x, final int y, final Image image) {
    PixelGrabber pixelGrabber;
    ColorModel colorModel;
    int width;
    int height;
    int[] pixels;
    boolean mayTransparent;
    image.flush();
    width = image.getWidth(null);
    height = image.getHeight(null);
    pixels = new int[width * height];
    pixelGrabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
    try {
        if (pixelGrabber.grabPixels() == true) {
            mayTransparent = true;
            colorModel = pixelGrabber.getColorModel();
            if (colorModel != null) {
                mayTransparent = colorModel.hasAlpha();
            }
            this.drawImage(x, y, pixels, width, height, mayTransparent);
        }
    } catch (final InterruptedException e) {
        Debug.printException(e, "Issue while extracting pixels");
    }
    pixels = null;
    colorModel = null;
    pixelGrabber = null;
}
Also used : ColorModel(java.awt.image.ColorModel) PixelGrabber(java.awt.image.PixelGrabber)

Example 58 with PixelGrabber

use of java.awt.image.PixelGrabber in project narchy by automenta.

the class ClipBMP method convertImage.

/*
     * convertImage converts the memory image to the bitmap format (BRG). It
     * also computes some information for the bitmap info header.
     *
     */
private boolean convertImage(Image parImage, int parWidth, int parHeight) {
    int pad;
    bitmap = new int[parWidth * parHeight];
    PixelGrabber pg = new PixelGrabber(parImage, 0, 0, parWidth, parHeight, bitmap, 0, parWidth);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        e.printStackTrace();
        return (false);
    }
    pad = (4 - ((parWidth * 3) % 4)) * parHeight;
    biSizeImage = ((parWidth * parHeight) * 3) + pad;
    bfSize = biSizeImage + BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
    biWidth = parWidth;
    biHeight = parHeight;
    return (true);
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 59 with PixelGrabber

use of java.awt.image.PixelGrabber in project cytoscape-impl by cytoscape.

the class ImageUtil method toBufferedImage.

public static BufferedImage toBufferedImage(final Image image) throws InterruptedException {
    if (image instanceof BufferedImage)
        return (BufferedImage) image;
    MediaTracker tracker = new MediaTracker(new Component() {
    });
    tracker.addImage(image, 0);
    tracker.waitForAll();
    PixelGrabber pixelGrabber = new PixelGrabber(image, 0, 0, -1, -1, false);
    pixelGrabber.grabPixels();
    ColorModel cm = pixelGrabber.getColorModel();
    final int w = pixelGrabber.getWidth();
    final int h = pixelGrabber.getHeight();
    WritableRaster raster = cm.createCompatibleWritableRaster(w, h);
    final BufferedImage renderedImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), new Hashtable());
    renderedImage.getRaster().setDataElements(0, 0, w, h, pixelGrabber.getPixels());
    return renderedImage;
}
Also used : MediaTracker(java.awt.MediaTracker) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) Hashtable(java.util.Hashtable) PixelGrabber(java.awt.image.PixelGrabber) Component(java.awt.Component) BufferedImage(java.awt.image.BufferedImage)

Example 60 with PixelGrabber

use of java.awt.image.PixelGrabber in project imagej1 by imagej.

the class ByteProcessorTest method testByteProcessorImage.

@Test
public void testByteProcessorImage() {
    java.awt.image.ColorModel cm = new ByteProcessor(width, height, getImageByteData(), null).getColorModel();
    byte[] pixels8 = getImageByteData();
    java.awt.image.MemoryImageSource source = new MemoryImageSource(width, height, cm, pixels8, 0, width);
    source.setAnimated(true);
    source.setFullBufferUpdates(true);
    java.awt.Image refImage = Toolkit.getDefaultToolkit().createImage(source);
    // find the test data
    byte[] testByteProcessor = new ByteProcessor(refImage).create8BitImage();
    // find the reference data
    PixelGrabber pg = new PixelGrabber(refImage, 0, 0, width, height, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        System.err.println(e);
    }
    byte[] refImageArray = (byte[]) pg.getPixels();
    // check the values
    for (int index = 0; index < refImageArray.length; index++) {
        // System.out.println( (refByteArray[index]&0xff) + " " + index + " " +  testByteProcessor.get(index) );
        assertEquals(refImageArray[index], testByteProcessor[index], 0.0);
    }
}
Also used : MemoryImageSource(java.awt.image.MemoryImageSource) ColorModel(java.awt.image.ColorModel) Image(java.awt.Image) PixelGrabber(java.awt.image.PixelGrabber) MemoryImageSource(java.awt.image.MemoryImageSource) Test(org.junit.Test)

Aggregations

PixelGrabber (java.awt.image.PixelGrabber)88 BufferedImage (java.awt.image.BufferedImage)37 ColorModel (java.awt.image.ColorModel)20 IOException (java.io.IOException)17 Image (java.awt.Image)13 Color (java.awt.Color)9 DirectColorModel (java.awt.image.DirectColorModel)7 MemoryImageSource (java.awt.image.MemoryImageSource)6 Point2D (java.awt.geom.Point2D)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 WritableRaster (java.awt.image.WritableRaster)2