use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class ProxyGraphics2D method getBufferedImageCopy.
/**
* Return a new <code>BufferedImage</code>
* that contains a copy of the provided
* <code>Image</code> where its
* transparent pixels have been replaced by
* <code>bgcolor</code>. If the new
* <code>BufferedImage</code> can not be created,
* probably because the original image has not
* finished loading, then <code>null</code> is
* returned.
*/
private BufferedImage getBufferedImageCopy(Image img, Color bgcolor) {
BufferedImage imageCopy = null;
int width = img.getWidth(null);
int height = img.getHeight(null);
if (width > 0 && height > 0) {
int imageType;
/* Try to minimize the depth of the BufferedImage
* we are about to create by, if possible, making
* it the same depth as the original image.
*/
if (img instanceof BufferedImage) {
BufferedImage bufImage = (BufferedImage) img;
imageType = bufImage.getType();
} else {
imageType = BufferedImage.TYPE_INT_ARGB;
}
imageCopy = new BufferedImage(width, height, imageType);
/* Copy the original image into the new buffer
* without any transformations.
* This will replace the transparent pixels
* in the original with background color.
*/
Graphics g = imageCopy.createGraphics();
g.drawImage(img, 0, 0, bgcolor, null);
g.dispose();
/* We couldn't get the width or height of the image
* so just return null.
*/
} else {
imageCopy = null;
}
return imageCopy;
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class NoResizeEventOnDMChangeTest method main.
public static void main(String[] args) {
final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (!gd.isFullScreenSupported()) {
System.out.println("Full screen not supported, test passed");
return;
}
DisplayMode dm = gd.getDisplayMode();
final DisplayMode[] dms = new DisplayMode[2];
for (DisplayMode dm1 : gd.getDisplayModes()) {
if (dm1.getWidth() != dm.getWidth() || dm1.getHeight() != dm.getHeight()) {
dms[0] = dm1;
break;
}
}
if (dms[0] == null) {
System.out.println("Test Passed: all DMs have same dimensions");
return;
}
dms[1] = dm;
Frame f = new Frame() {
@Override
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.green);
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
};
f.setUndecorated(true);
testFSWindow(gd, dms, f);
Window w = new Window(f) {
@Override
public void paint(Graphics g) {
g.setColor(Color.magenta);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.cyan);
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
};
testFSWindow(gd, dms, w);
System.out.println("Test Passed.");
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class OpCompatibleImageTest method createTestImage.
private BufferedImage createTestImage(int type) {
BufferedImage img = new BufferedImage(100, 100, type);
Graphics g = img.createGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
g.dispose();
return img;
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class HiDPIPropertiesWindowsTest method testScale.
private static void testScale(double scaleX, double scaleY) {
Dialog dialog = new Dialog((Frame) null, true) {
@Override
public void paint(Graphics g) {
super.paint(g);
AffineTransform tx = ((Graphics2D) g).getTransform();
dispose();
if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) {
throw new RuntimeException(String.format("Wrong scale:" + "[%f, %f] instead of [%f, %f].", tx.getScaleX(), tx.getScaleY(), scaleX, scaleY));
}
}
};
dialog.setSize(200, 300);
dialog.setVisible(true);
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class DrawImageCoordsTest method main.
public static void main(String[] args) {
/* Create an image to draw, filled in solid red. */
BufferedImage srcImg = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics srcG = srcImg.createGraphics();
srcG.setColor(Color.red);
int w = srcImg.getWidth(null);
int h = srcImg.getHeight(null);
srcG.fillRect(0, 0, w, h);
/* Create a destination image */
BufferedImage dstImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D dstG = dstImage.createGraphics();
/* draw image under a scaling transform that overflows int */
AffineTransform tx = new AffineTransform(0.5, 0, 0, 0.5, 0, 5.8658460197478485E9);
dstG.setTransform(tx);
dstG.drawImage(srcImg, 0, 0, null);
/* draw image under the same overflowing transform, cancelling
* out the 0.5 scale on the graphics
*/
dstG.drawImage(srcImg, 0, 0, 2 * w, 2 * h, null);
if (Color.red.getRGB() == dstImage.getRGB(w / 2, h / 2)) {
throw new RuntimeException("Unexpected color: clipping failed.");
}
System.out.println("Test Thread Completed");
}
Aggregations