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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations