Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarolyn MacLeod2011-04-28 15:55:18 +0000
committerCarolyn MacLeod2011-04-28 15:55:18 +0000
commitedbeecf85277c591bfb2bc972fa515731aa4a181 (patch)
tree35982cd75d6758e26ff82ebc22094d5273b1ae23 /examples/org.eclipse.swt.snippets/src
parent46397882f1d2aa4b047ece1d2e65b2601f3f9ca2 (diff)
downloadeclipse.platform.swt-edbeecf85277c591bfb2bc972fa515731aa4a181.tar.gz
eclipse.platform.swt-edbeecf85277c591bfb2bc972fa515731aa4a181.tar.xz
eclipse.platform.swt-edbeecf85277c591bfb2bc972fa515731aa4a181.zip
add image scaling snippet
Diffstat (limited to 'examples/org.eclipse.swt.snippets/src')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet355.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet355.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet355.java
new file mode 100644
index 0000000000..d7041cb66b
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet355.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.snippets;
+
+/*
+ * draw an image and scale it to half size and double size
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+public class Snippet355 {
+ public static void main (String [] args) {
+ Display display = new Display ();
+ Shell shell = new Shell (display, SWT.SHELL_TRIM);
+ final Image image = display.getSystemImage (SWT.ICON_QUESTION);
+ shell.addListener (SWT.Paint, new Listener () {
+ public void handleEvent (Event e) {
+ Rectangle rect = image.getBounds ();
+ int width = rect.width;
+ int height = rect.height;
+ GC gc = e.gc;
+ int x = 10, y = 10;
+ gc.drawImage (image, 0, 0, width, height, x, y, width, height);
+ gc.drawImage (image, 0, 0, width, height, x + width, y, (int)Math.round(width * 0.5), (int)Math.round(height * 0.5));
+ gc.drawImage (image, 0, 0, width, height, x+width+(int)Math.round(width * 0.5), y, width * 2, height * 2);
+ }
+ });
+ shell.setSize (600, 400);
+ shell.open ();
+ while (!shell.isDisposed ()) {
+ if (!display.readAndDispatch ())
+ display.sleep ();
+ }
+ display.dispose ();
+ }
+}
+

Back to the top