use of java.awt.image in project JMRI by JMRI.
the class LcdClockFrame method scaleImage.
// Added method to scale the clock digit images to fit the
// size of the display window
public void scaleImage() {
int iconHeight;
int iconWidth;
int frameHeight = this.getContentPane().getSize().height;
int frameWidth = this.getContentPane().getSize().width;
if ((double) frameWidth / (double) frameHeight > aspect) {
iconHeight = frameHeight;
iconWidth = (int) (iconAspect * iconHeight);
} else {
//this DOES NOT allow space for the Run/Stop button, if it is
//enabled. When the Run/Stop button is enabled, the layout will have to be changed
iconWidth = (int) (frameWidth / 4.5);
iconHeight = (int) (iconWidth / iconAspect);
}
for (int i = 0; i < 10; i++) {
Image scaledImage = baseTubes[i].getImage().getScaledInstance(iconWidth, iconHeight, Image.SCALE_SMOOTH);
tubes[i].setImage(scaledImage);
}
Image scaledImage = baseColon.getImage().getScaledInstance(iconWidth / 2, iconHeight, Image.SCALE_SMOOTH);
colonIcon.setImage(scaledImage);
// Ugly hack to force frame to redo the layout.
// Without this the image is scaled but the label size and position doesn't change.
// doLayout() doesn't work either
this.setVisible(false);
this.remove(b);
if (clock.getShowStopButton()) {
// pick up clock prefs choice
this.getContentPane().add(b);
}
this.setVisible(true);
return;
}
use of java.awt.image in project jdk8u_jdk by JetBrains.
the class MultiResolutionDisabledImageTest method main.
public static void main(String[] args) throws Exception {
Image baseMRImage = new BaseMultiResolutionImage(createImage(1), createImage(2));
testMRDisabledImage(baseMRImage);
saveImages();
Image toolkitMRImage = Toolkit.getDefaultToolkit().getImage(IMAGE_NAME_1X);
if (toolkitMRImage instanceof MultiResolutionImage) {
testMRDisabledImage(toolkitMRImage);
}
}
use of java.awt.image in project jdk8u_jdk by JetBrains.
the class ClassCastExceptionForInvalidSurface method main.
public static void main(final String[] args) throws InterruptedException {
// Catch all uncaught exceptions and treat them as test failure
Thread.setDefaultUncaughtExceptionHandler((t, e) -> failed = e);
// Data for rendering
BufferedImage bi = new BufferedImage(10, 10, TYPE_INT_ARGB);
FontRenderContext frc = new FontRenderContext(null, false, false);
Font font = new Font("Serif", Font.PLAIN, 12);
GlyphVector gv = font.createGlyphVector(frc, new char[] { 'a', '1' });
Thread t1 = new Thread(() -> {
while (!isComplete()) {
vi = gc.createCompatibleVolatileImage(10, 10);
if (!list.offer(vi)) {
vi.flush();
}
}
list.forEach(Image::flush);
});
Thread t2 = new Thread(() -> {
while (!isComplete()) {
VolatileImage vi = list.poll();
if (vi != null) {
vi.flush();
}
}
});
Thread t3 = new Thread(() -> {
while (!isComplete()) {
vi.createGraphics().drawImage(bi, 1, 1, null);
}
});
Thread t4 = new Thread(() -> {
while (!isComplete()) {
vi.createGraphics().drawGlyphVector(gv, 0, 0);
vi.createGraphics().drawOval(0, 0, 10, 10);
vi.createGraphics().drawLine(0, 0, 10, 10);
vi.createGraphics().drawString("123", 1, 1);
vi.createGraphics().draw(new Rectangle(0, 0, 10, 10));
vi.createGraphics().fillOval(0, 0, 10, 10);
final Graphics2D graphics = vi.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.fillPolygon(new int[] { 0, 10, 10, 0 }, new int[] { 0, 0, 10, 10 }, 4);
}
});
t1.start();
t2.start();
t3.start();
t4.start();
t1.join();
t2.join();
t3.join();
t4.join();
if (failed != null) {
System.err.println("Test failed");
failed.printStackTrace();
}
}
use of java.awt.image in project jdk8u_jdk by JetBrains.
the class NonOpaqueDestLCDAATest method render.
public void render(Graphics g, int w, int h) {
initImages(w, h);
g.setColor(new Color(0xAD, 0xD8, 0xE6));
g.fillRect(0, 0, w, h);
Graphics2D g2d = (Graphics2D) g.create();
for (Image im : images) {
g2d.drawImage(im, 0, 0, null);
g2d.translate(0, im.getHeight(null));
}
}
use of java.awt.image in project processdash by dtuma.
the class ImageResizingGraphics method drawImage.
public boolean drawImage(Image image, int x, int y, ImageObserver observer) {
AffineTransform transform = getTransform();
if (transform == null || ((transform.getType() & AffineTransform.TYPE_MASK_SCALE) == 0))
return delegate.drawImage(image, x, y, observer);
else {
double scaleX = transform.getScaleX();
double scaleY = transform.getScaleY();
AffineTransform newTransform = new AffineTransform(transform);
newTransform.scale(1 / scaleX, 1 / scaleY);
setTransform(newTransform);
int width = image.getWidth(observer);
int height = image.getHeight(observer);
// workaround for Java bug 4937376
Image img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
img.getGraphics().drawImage(image, 0, 0, null);
img = img.getScaledInstance((int) Math.round(width * scaleX), (int) Math.round(height * scaleY), Image.SCALE_SMOOTH);
boolean result = delegate.drawImage(img, x, y, null);
setTransform(transform);
return result;
}
}
Aggregations