Search in sources :

Example 16 with PixelGrabber

use of java.awt.image.PixelGrabber in project java-swing-tips by aterai.

the class GradientPalletProgressBarUI method makeGradientPallet.

private static int[] makeGradientPallet() {
    BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    Point2D start = new Point2D.Float();
    Point2D end = new Point2D.Float(99f, 0f);
    float[] dist = { 0f, .5f, 1f };
    Color[] colors = { Color.RED, Color.YELLOW, Color.GREEN };
    g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
    g2.fillRect(0, 0, 100, 1);
    g2.dispose();
    int width = image.getWidth(null);
    int[] pallet = new int[width];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException ex) {
        ex.printStackTrace();
        Toolkit.getDefaultToolkit().beep();
        Thread.currentThread().interrupt();
    }
    return pallet;
}
Also used : Point2D(java.awt.geom.Point2D) PixelGrabber(java.awt.image.PixelGrabber) BufferedImage(java.awt.image.BufferedImage)

Example 17 with PixelGrabber

use of java.awt.image.PixelGrabber in project java-swing-tips by aterai.

the class MissingIcon method makeRoundedMemoryImageSource.

private static Optional<MemoryImageSource> makeRoundedMemoryImageSource(Image img, int w, int h) {
    int[] pix = new int[h * w];
    PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
    try {
        pg.grabPixels();
    } catch (InterruptedException ex) {
        System.err.println("interrupted waiting for pixels!");
        ex.printStackTrace();
        Thread.currentThread().interrupt();
        return Optional.empty();
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or error");
        return Optional.empty();
    }
    Area area = makeNorthWestCorner();
    Rectangle r = area.getBounds();
    // NW
    Shape s = area;
    for (int y = 0; y < r.height; y++) {
        for (int x = 0; x < r.width; x++) {
            if (s.contains(x, y)) {
                pix[x + y * w] = 0x0;
            }
        }
    }
    AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d);
    at.translate(-w, 0);
    // NE
    s = at.createTransformedShape(area);
    for (int y = 0; y < r.height; y++) {
        for (int x = w - r.width; x < w; x++) {
            if (s.contains(x, y)) {
                pix[x + y * w] = 0x0;
            }
        }
    }
    return Optional.of(new MemoryImageSource(w, h, pix, 0, w));
}
Also used : Area(java.awt.geom.Area) PixelGrabber(java.awt.image.PixelGrabber) AffineTransform(java.awt.geom.AffineTransform) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 18 with PixelGrabber

use of java.awt.image.PixelGrabber in project java-swing-tips by aterai.

the class ProgressListener method makeGradientPallet.

private static int[] makeGradientPallet(int range) {
    BufferedImage image = new BufferedImage(range, 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    Point2D start = new Point2D.Float();
    Point2D end = new Point2D.Float(range - 1f, 0f);
    float[] dist = { 0f, .8f, .9f, 1f };
    Color[] colors = { Color.GREEN, Color.YELLOW, Color.ORANGE, Color.RED };
    g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
    g2.fillRect(0, 0, range, 1);
    g2.dispose();
    int width = image.getWidth(null);
    int[] pallet = new int[width];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException ex) {
        ex.printStackTrace();
        Toolkit.getDefaultToolkit().beep();
        Thread.currentThread().interrupt();
    }
    return pallet;
}
Also used : Point2D(java.awt.geom.Point2D) PixelGrabber(java.awt.image.PixelGrabber) BufferedImage(java.awt.image.BufferedImage)

Example 19 with PixelGrabber

use of java.awt.image.PixelGrabber in project openchemlib by Actelion.

the class WMFGraphics method setGDIFillBrush.

public int setGDIFillBrush() {
    int i = brushhandle;
    if (brushfillstyle == 3) {
        if (brushpattern != null) {
            int j = brushpattern.getWidth(null);
            int k = brushpattern.getHeight(null);
            int[] ai = new int[j * k];
            PixelGrabber pixelgrabber = new PixelGrabber(brushpattern, 0, 0, j, k, ai, 0, j);
            try {
                pixelgrabber.grabPixels();
                if ((pixelgrabber.status() & 0x80) != 0) {
                    brushhandle = wmf.createBrushIndirect(0, foreground, brushhatch);
                } else {
                    brushhandle = wmf.createPatternBrush(ai, j, k);
                }
            } catch (InterruptedException _ex) {
                brushhandle = wmf.createBrushIndirect(0, foreground, brushhatch);
            }
        } else {
            brushhandle = wmf.createBrushIndirect(0, foreground, brushhatch);
        }
    } else {
        brushhandle = wmf.createBrushIndirect(brushfillstyle, foreground, brushhatch);
    }
    wmf.selectObject(brushhandle);
    wmf.deleteObject(i);
    state.setBrush(brushhandle);
    return brushhandle;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 20 with PixelGrabber

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

the class ImageUtil method getImageSpritePixels.

/**
 * Converts the buffered image into a sprite image and returns it
 * @param image  The image to be converted
 * @param client Current client instance
 * @return       The buffered image as a sprite image
 */
public static SpritePixels getImageSpritePixels(BufferedImage image, Client client) {
    int[] pixels = new int[image.getWidth() * image.getHeight()];
    try {
        PixelGrabber g = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
        g.setColorModel(new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000));
        g.grabPixels();
        // check for == 0, not actual transparency
        for (int i = 0; i < pixels.length; i++) {
            if ((pixels[i] & 0xFF000000) == 0) {
                pixels[i] = 0;
            }
        }
    } catch (InterruptedException ex) {
        log.debug("PixelGrabber was interrupted: ", ex);
    }
    return client.createSpritePixels(pixels, image.getWidth(), image.getHeight());
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) PixelGrabber(java.awt.image.PixelGrabber)

Aggregations

PixelGrabber (java.awt.image.PixelGrabber)39 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 DirectColorModel (java.awt.image.DirectColorModel)3 ByteProcessor (ij.process.ByteProcessor)2 MediaTracker (java.awt.MediaTracker)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