Search in sources :

Example 61 with java.awt.image

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();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) org.eclipse.swt.graphics(org.eclipse.swt.graphics) Image(java.awt.Image) Point(org.eclipse.swt.graphics.Point) org.eclipse.swt(org.eclipse.swt)

Example 62 with java.awt.image

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) IOException(java.io.IOException) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 63 with java.awt.image

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) VTOL(megamek.common.VTOL) Image(java.awt.Image) File(java.io.File) Tank(megamek.common.Tank)

Example 64 with java.awt.image

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) Image(java.awt.Image) File(java.io.File)

Example 65 with java.awt.image

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) Image(java.awt.Image) File(java.io.File)

Aggregations

Image (java.awt.Image)515 BufferedImage (java.awt.image.BufferedImage)263 ImageIcon (javax.swing.ImageIcon)127 Graphics2D (java.awt.Graphics2D)97 IOException (java.io.IOException)73 File (java.io.File)64 Point (java.awt.Point)53 URL (java.net.URL)51 Graphics (java.awt.Graphics)46 JLabel (javax.swing.JLabel)31 Dimension (java.awt.Dimension)28 Rectangle (java.awt.Rectangle)27 AffineTransform (java.awt.geom.AffineTransform)25 Color (java.awt.Color)24 Test (org.junit.Test)24 RenderedImage (java.awt.image.RenderedImage)21 ArrayList (java.util.ArrayList)21 Toolkit (java.awt.Toolkit)20 IIOImage (javax.imageio.IIOImage)18 MediaTracker (java.awt.MediaTracker)17