Search in sources :

Example 31 with VolatileImage

use of java.awt.image.VolatileImage in project darkFunction-Editor by darkFunction.

the class SpriteGraphic method createVImage.

private VolatileImage createVImage() {
    VolatileImage vi = ImageUtil.createVolatileImage(subRect.width, subRect.height, Transparency.TRANSLUCENT);
    if (vi == null)
        return null;
    Graphics2D g2d = (Graphics2D) vi.getGraphics();
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 1));
    g2d.fillRect(0, 0, subRect.width, subRect.height);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.drawImage(bImage, 0, 0, subRect.width, subRect.height, subRect.x, subRect.y, subRect.x + subRect.width, subRect.y + subRect.height, null);
    return vi;
}
Also used : VolatileImage(java.awt.image.VolatileImage)

Example 32 with VolatileImage

use of java.awt.image.VolatileImage in project darkFunction-Editor by darkFunction.

the class SpriteGraphic method draw.

public void draw(Graphics g, Point aPoint, float aScale, boolean bDrawSelectedMode) {
    Rectangle r = getRect();
    Rectangle dest = new Rectangle(aPoint.x + ((int) (r.x * aScale)), aPoint.y + ((int) (r.y * aScale)), (int) (r.width * aScale), (int) (r.height * aScale));
    if (vImage != null) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
        int valid = vImage.validate(gc);
        if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
            vImage = createVImage();
        }
        Point topLeft = new Point(dest.x, dest.y);
        Point bottomRight = new Point(dest.x + dest.width, dest.y + dest.height);
        if (_hFlip) {
            topLeft.x = dest.x + dest.width;
            bottomRight.x = dest.x;
        }
        if (_vFlip) {
            topLeft.y = dest.y + dest.height;
            bottomRight.y = dest.y;
        }
        VolatileImage img = null;
        if (bDrawSelectedMode && isSelected()) {
            if (selectedVImage == null || selectedVImage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
                selectedVImage = this.createSelectedVImage();
            }
            img = selectedVImage;
        } else {
            img = vImage;
        }
        g.drawImage(img, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y, 0, 0, subRect.width, subRect.height, null);
    }
    if (bDrawSelectedMode && isSelected()) {
        g.setColor(new Color(0, 0, 0, 100));
        g.drawRect(dest.x, dest.y, dest.width, dest.height);
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage)

Example 33 with VolatileImage

use of java.awt.image.VolatileImage in project darkFunction-Editor by darkFunction.

the class ImageUtil method createVolatileImage.

public static VolatileImage createVolatileImage(int width, int height, int transparency) {
    if (width == 0 || height == 0)
        return null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage image = null;
    image = gc.createCompatibleVolatileImage(width, height, transparency);
    int valid = image.validate(gc);
    if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
        image = createVolatileImage(width, height, transparency);
    }
    return image;
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 34 with VolatileImage

use of java.awt.image.VolatileImage in project darkFunction-Editor by darkFunction.

the class ImageUtil method createVolatileImage.

public static VolatileImage createVolatileImage(BufferedImage bi) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vimage = createVolatileImage(bi.getWidth(), bi.getHeight(), java.awt.Transparency.TRANSLUCENT);
    java.awt.Graphics2D g = null;
    try {
        g = vimage.createGraphics();
        // clear to transparent
        g.setComposite(AlphaComposite.Src);
        g.setColor(new Color(0, 0, 0, 0));
        g.fillRect(0, 0, vimage.getWidth(), vimage.getHeight());
        g.drawImage(bi, null, 0, 0);
    } finally {
        g.dispose();
    }
    return vimage;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Color(java.awt.Color) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 35 with VolatileImage

use of java.awt.image.VolatileImage in project javatari by ppeccin.

the class SwingHelper method asCompatibleVolatileImage.

public static VolatileImage asCompatibleVolatileImage(Image img, int transparency) {
    VolatileImage ret = defaultScreenDeviceConfiguration().createCompatibleVolatileImage(img.getWidth(null), img.getHeight(null), transparency);
    Graphics2D gc = ret.createGraphics();
    gc.setComposite(AlphaComposite.Src);
    gc.drawImage(img, 0, 0, null);
    gc.dispose();
    return ret;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Graphics2D(java.awt.Graphics2D)

Aggregations

VolatileImage (java.awt.image.VolatileImage)53 GraphicsConfiguration (java.awt.GraphicsConfiguration)30 BufferedImage (java.awt.image.BufferedImage)29 Graphics2D (java.awt.Graphics2D)24 GraphicsEnvironment (java.awt.GraphicsEnvironment)21 Graphics (java.awt.Graphics)6 AffineTransform (java.awt.geom.AffineTransform)6 Rectangle (java.awt.Rectangle)5 File (java.io.File)5 GraphicsDevice (java.awt.GraphicsDevice)3 Shape (java.awt.Shape)3 IOException (java.io.IOException)3 DestSurfaceProvider (sun.java2d.DestSurfaceProvider)3 Surface (sun.java2d.Surface)3 AWTException (java.awt.AWTException)2 Font (java.awt.Font)2 GradientPaint (java.awt.GradientPaint)2 Image (java.awt.Image)2 ImageCapabilities (java.awt.ImageCapabilities)2 Paint (java.awt.Paint)2