use of java.awt.image in project eclipse.platform.swt by eclipse.
the class Snippet361 method performPrintAction.
private static void performPrintAction(final Display display, final Shell shell) {
Rectangle r = composite.getBounds();
Point p = shell.toDisplay(r.x, r.y);
org.eclipse.swt.graphics.Image snapshotImage = new org.eclipse.swt.graphics.Image(display, r.width - 2, r.height - 2);
GC snapshotGC = new GC(display);
snapshotGC.copyArea(snapshotImage, p.x + 1, p.y + 1);
PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
PrinterData data = new PrinterData();
data.orientation = PrinterData.LANDSCAPE;
dialog.setPrinterData(data);
data = dialog.open();
if (data != null) {
Printer printer = new Printer(data);
Point screenDPI = display.getDPI();
Point printerDPI = printer.getDPI();
int scaleFactor = printerDPI.x / screenDPI.x;
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
if (printer.startJob("Print Image")) {
ImageData imageData = snapshotImage.getImageData();
org.eclipse.swt.graphics.Image printerImage = new org.eclipse.swt.graphics.Image(printer, imageData);
GC printerGC = new GC(printer);
if (printer.startPage()) {
printerGC.drawImage(printerImage, 0, 0, imageData.width, imageData.height, -trim.x, -trim.y, scaleFactor * imageData.width, scaleFactor * imageData.height);
printer.endPage();
}
printerGC.dispose();
printer.endJob();
}
printer.dispose();
}
snapshotImage.dispose();
snapshotGC.dispose();
}
use of java.awt.image in project eclipse.platform.swt by eclipse.
the class Bug164015_G2DDrawImage method loadTile.
public BufferedImage loadTile(int x, int y) {
String file_path = "tile_" + x + "_" + y + ".gif";
BufferedImage bufferedImage = null;
if (USE_JAI_FOR_IMAGE_IO) {
try {
bufferedImage = ImageIO.read(new File(file_path));
} catch (IOException e) {
bufferedImage = null;
}
} else {
// use AWT
Image image = new ImageIcon(file_path).getImage();
if (image.getWidth(null) <= 0 || image.getHeight(null) <= 0) {
return null;
}
bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
bufferedImage.getGraphics().drawImage(image, 0, 0, null);
}
return bufferedImage;
}
use of java.awt.image in project megameklab by MegaMek.
the class ImageHelperVehicle method getTableImage.
public static Image getTableImage(Entity unit) {
Image table = null;
String path = new File(ImageHelper.recordSheetPath).getAbsolutePath() + File.separatorChar;
if (unit instanceof VTOL) {
table = new ImageIcon(path + "twvee-vtoltables.png").getImage();
} else if (unit instanceof Tank) {
table = new ImageIcon(path + "twvee-groundtables.png").getImage();
}
return table;
}
use of java.awt.image in project megameklab by MegaMek.
the class ImageHelper method getFluffImage.
public static Image getFluffImage(String image) {
if ((image == null) || (image.trim().length() < 1)) {
return null;
}
Image fluff = null;
String path = new File(fluffPath).getAbsolutePath() + File.separatorChar + image;
if (!(new File(path).exists())) {
path = new File(image).getAbsolutePath();
if (!(new File(path).exists())) {
return null;
}
}
fluff = new ImageIcon(path).getImage();
return fluff;
}
use of java.awt.image in project megameklab by MegaMek.
the class ImageHelper method getGyroPipImage.
public static Image getGyroPipImage() {
String path = new File(recordSheetPath).getAbsolutePath() + File.separatorChar;
Image image = new ImageIcon(path + "gyropip.png").getImage();
return image;
}
Aggregations