From b6410288131170760e7e74faa91b50a6557c1482 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Fri, 12 Aug 2022 10:44:29 +0200 Subject: debugDisplayImage for SWT --- .../at/asit/pdfover/commons/utils/ImageUtil.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'pdf-over-commons/src/main/java/at/asit') diff --git a/pdf-over-commons/src/main/java/at/asit/pdfover/commons/utils/ImageUtil.java b/pdf-over-commons/src/main/java/at/asit/pdfover/commons/utils/ImageUtil.java index 416e0157..6855a62a 100644 --- a/pdf-over-commons/src/main/java/at/asit/pdfover/commons/utils/ImageUtil.java +++ b/pdf-over-commons/src/main/java/at/asit/pdfover/commons/utils/ImageUtil.java @@ -11,9 +11,17 @@ import java.awt.image.DirectColorModel; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.PaletteData; import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; import javax.imageio.ImageIO; import javax.imageio.ImageReadParam; @@ -167,6 +175,28 @@ public final class ImageUtil { return image; } + public static org.eclipse.swt.graphics.Image debugDisplayImage(org.eclipse.swt.graphics.Image image) { + Display display = Display.getDefault(); + Shell shell = new Shell(display, SWT.CLOSE); + shell.setLayout(new FormLayout()); + + Rectangle imgBounds = image.getBounds(); + Label imgLabel = new Label(shell, SWT.NATIVE); + FormData imgFD = new FormData(); + imgFD.left = new FormAttachment(0); + imgFD.top = new FormAttachment(0); + imgFD.width = imgBounds.width; + imgFD.height = imgBounds.height; + imgLabel.setLayoutData(imgFD); + imgLabel.setImage(image); + + shell.setSize(imgBounds.width + 20, imgBounds.height + 60); + + shell.open(); + shell.forceActive(); + return image; + } + /** * Convert AWT Image to SWT Image * -- cgit v1.2.3