use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class JPEGsNotAcceleratedTest method showRes.
private static void showRes(String desc, final BufferedImage src) {
final int w = src.getWidth();
final int h = src.getHeight();
Frame f = new Frame(desc + ": dbl-click to exit");
Component c;
f.add(c = new Component() {
public Dimension getPreferredSize() {
return new Dimension(w, h);
}
public void paint(Graphics g) {
g.clearRect(0, 0, getWidth(), getHeight());
g.drawImage(src, 0, 0, null);
}
});
c.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
System.exit(0);
}
}
});
f.pack();
synchronized (JPEGsNotAcceleratedTest.class) {
f.setLocation(frameX, frameY);
frameX += f.getWidth();
if ((frameX + f.getWidth()) > f.getGraphicsConfiguration().getBounds().width) {
frameY += TEST_H;
if ((frameY + f.getHeight()) > f.getGraphicsConfiguration().getBounds().height) {
startY += 30;
startX += 30;
frameY = startY;
}
frameX = startX;
}
}
;
f.setVisible(true);
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class JPEGsNotAcceleratedTest method writeTestImage.
public static void writeTestImage(String fileName) {
BufferedImage bi = new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.setColor(new Color(testRGB));
g.fillRect(0, 0, TEST_W, TEST_H);
try {
System.err.printf("Writing %s\n", fileName);
if (lowCompression) {
ImageWriter iw = (ImageWriter) ImageIO.getImageWritersBySuffix("jpeg").next();
if (iw == null) {
throw new RuntimeException("No available image writer for " + "jpeg " + " Test failed.");
}
File file = new File(fileName);
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
ImageWriteParam param = iw.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(1);
IIOImage iioImg = new IIOImage(bi, null, null);
iw.write(null, iioImg, param);
} else {
ImageIO.write(bi, "jpeg", new File(fileName));
}
} catch (IOException e) {
System.err.println("Error " + e + " when writing file: " + fileName);
throw new RuntimeException(e);
}
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class ValidWbmpTest method main.
public static void main(String[] args) {
try {
String[] formats = { "JPEG", "PNG", "BMP" };
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);
Graphics g = img.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.black);
g.fillRect(10, 10, 80, 80);
ImageReader ir = (ImageReader) ImageIO.getImageReadersByFormatName("WBMP").next();
if (ir == null) {
throw new RuntimeException("No readers for WBMP format!");
}
for (int i = 0; i < formats.length; i++) {
System.out.println("Test " + formats[i] + " stream...");
boolean passed = false;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, formats[i], baos);
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = null;
iis = ImageIO.createImageInputStream(bais);
ir.setInput(iis);
try {
BufferedImage res = ir.read(0);
} catch (IIOException e) {
StackTraceElement[] stack = e.getStackTrace();
if (ir.getClass().getName().equals(stack[0].getClassName()) && "readHeader".equals(stack[0].getMethodName())) {
passed = true;
}
} catch (Throwable t) {
t.printStackTrace();
}
if (!passed) {
throw new RuntimeException("Test failed!");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Unexpected exception. Test failed.");
}
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class bug8057791 method main.
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
final int listWidth = 50;
final int listHeight = 50;
final int selCellIndex = 0;
JList<String> list = new JList<String>();
list.setSize(listWidth, listHeight);
DefaultListModel<String> listModel = new DefaultListModel<String>();
listModel.add(selCellIndex, "E");
list.setModel(listModel);
list.setSelectedIndex(selCellIndex);
BufferedImage img = new BufferedImage(listWidth, listHeight, BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
list.paint(g);
g.dispose();
Rectangle cellRect = list.getCellBounds(selCellIndex, selCellIndex);
HashSet<Color> cellColors = new HashSet<Color>();
int uniqueColorIndex = 0;
for (int x = cellRect.x; x < (cellRect.x + cellRect.width); x++) {
for (int y = cellRect.y; y < (cellRect.y + cellRect.height); y++) {
Color cellColor = new Color(img.getRGB(x, y), true);
if (cellColors.add(cellColor)) {
System.err.println(String.format("Cell color #%d: %s", uniqueColorIndex++, cellColor));
}
}
}
Color selForegroundColor = list.getSelectionForeground();
Color selBackgroundColor = list.getSelectionBackground();
if (!cellColors.contains(new Color(selForegroundColor.getRGB(), true))) {
throw new RuntimeException(String.format("Selected cell is drawn without selection foreground color '%s'.", selForegroundColor));
}
if (!cellColors.contains(new Color(selBackgroundColor.getRGB(), true))) {
throw new RuntimeException(String.format("Selected cell is drawn without selection background color '%s'.", selBackgroundColor));
}
}
});
} catch (UnsupportedLookAndFeelException | InterruptedException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class bug7181438 method createBufferedImage.
private static BufferedImage createBufferedImage() {
final BufferedImage bi = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB);
final Graphics bg = bi.getGraphics();
//Black color and alpha = 0
bg.setColor(new Color(0, 0, 0, 0));
bg.fillRect(0, 0, SIZE, SIZE);
bg.dispose();
return bi;
}
Aggregations