Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 272988 Details for
Bug 97506
[HiDPI] ImageData.scaledTo() should use a better interpolation method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
The SnippetScaling enhanced by AWT scaling
SnippetScalingWithAWT.java (text/plain), 11.86 KB, created by
Conrad Groth
on 2018-03-03 08:46:08 EST
(
hide
)
Description:
The SnippetScaling enhanced by AWT scaling
Filename:
MIME Type:
Creator:
Conrad Groth
Created:
2018-03-03 08:46:08 EST
Size:
11.86 KB
patch
obsolete
>package org.eclipse.swt.snippets; >import java.awt.*; >import java.awt.image.*; >import java.io.*; > >import javax.imageio.*; > >/******************************************************************************* > * Copyright (c) 2000, 2016 IBM Corporation and others. > * All rights reserved. This Example Content is intended to demonstrate > * usage of Eclipse technology. It is provided to you under the terms and > * conditions of the Eclipse Distribution License v1.0 which is available > * at http://www.eclipse.org/org/documents/edl-v10.php > * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ >import org.eclipse.swt.*; >import org.eclipse.swt.graphics.*; >import org.eclipse.swt.graphics.Image; >import org.eclipse.swt.graphics.Rectangle; >import org.eclipse.swt.layout.*; >import org.eclipse.swt.widgets.*; >import org.eclipse.swt.widgets.Canvas; >import org.eclipse.swt.widgets.Composite; >import org.eclipse.swt.widgets.Event; >import org.eclipse.swt.widgets.Label; > >/** > * Draw images scaled to 0.5, 1, 1.25, 1.5, and 2 times original size. > */ >public class SnippetScalingWithAWT { > public static void main (String [] args) { > Display display = new Display (); > Shell shell = new Shell (display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); > shell.setLayout(new RowLayout(SWT.HORIZONTAL)); > > createImages(createColumn(shell), new Image(display, "bin/org/eclipse/swt/snippets/eclipse16.png")); > createImages(createColumn(shell), new Image(display, "bin/org/eclipse/swt/snippets/warning.gif")); > createImages(createColumn(shell), "bin/org/eclipse/swt/snippets/eclipse16.png"); > createImages(createColumn(shell), "bin/org/eclipse/swt/snippets/warning.gif"); > createImages(createColumn(shell), display.getSystemImage (SWT.ICON_INFORMATION)); > createImages(createColumn(shell), display.getSystemImage (SWT.ICON_WARNING)); > createImages(createColumn(shell), display.getSystemImage (SWT.ICON_ERROR)); > createImages(createColumn(shell), display.getSystemImage (SWT.ICON_QUESTION)); > > final Image triangleCircle = new Image(display, 16, 16); > GC gc = new GC(triangleCircle); > gc.drawPolyline(new int[] { 0,0, 15,0, 0,15, 0,0 }); > gc.drawOval(2, 2, 11, 11); > gc.dispose(); > createImages(createColumn(shell), triangleCircle); > > shell.pack (); > shell.open (); > while (!shell.isDisposed ()) { > if (!display.readAndDispatch ()) > display.sleep (); > } > display.dispose (); > } > > private static Composite createColumn(Composite parent) { > Composite column = new Composite(parent, SWT.NONE); > column.setLayout(new FillLayout(SWT.VERTICAL)); > return column; > } > > > private static void createImages(Composite parent, final String filename) { > try { > Display display = parent.getDisplay(); > java.awt.Image image = ImageIO.read(new File(filename)); > > Composite datas = new Composite(parent, SWT.NONE); > RowLayout rowLayout = new RowLayout(); > rowLayout.marginTop = rowLayout.marginLeft = 10; > rowLayout.spacing = 0; > datas.setLayout(rowLayout); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(image, 0.5)))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(image, 1.0)))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(image, 1.25)))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(image, 1.5)))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(image, 2.0)))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(image, 3.0)))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(image, 4.0)))); > } catch (IOException e) { > e.printStackTrace(); > } > > } > > private static void createImages(Composite parent, final Image image) { > Display display = parent.getDisplay(); > > BufferedImage awtImage = Snippet156.convertToAWT(image.getImageData()); > > > // ImageData#scaledTo(..) > Composite datas = new Composite(parent, SWT.NONE); > RowLayout rowLayout = new RowLayout(); > rowLayout.marginTop = rowLayout.marginLeft = 10; > rowLayout.spacing = 0; > datas.setLayout(rowLayout); > Rectangle bounds = image.getBounds(); > try { > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(awtImage, > (int) Math.round(bounds.width * 0.5) , (int) Math.round(bounds.height * 0.5))))); > new Label(datas, SWT.NONE).setImage(image); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(awtImage, > (int) Math.round(bounds.width * 1.25) , (int) Math.round(bounds.height * 1.25))))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(awtImage, > (int) Math.round(bounds.width * 1.5) , (int) Math.round(bounds.height * 1.5))))); > new Label(datas, SWT.NONE).setImage(new Image(display, Snippet156.convertToSWT(createResizedCopy(awtImage, > bounds.width * 2 , bounds.height * 2)))); > } catch (Exception e) { > System.err.println("Esception occured " + e); > new Label(datas, SWT.NONE).setText("Exception occured"); > } > > // Canvas SWT.Paint > Canvas paint = new Canvas(parent, SWT.NONE); > paint.addListener (SWT.Paint, new Listener () { > @Override > 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; > int w = 0; > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 0.5), (int)Math.round(height * 0.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width, height); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.25), (int)Math.round(height * 1.25)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.5), (int)Math.round(height * 1.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width * 2, height * 2); > } > }); > > // Canvas SWT.Paint with Antialias > Canvas paintAnti = new Canvas(parent, SWT.NONE); > paintAnti.addListener (SWT.Paint, new Listener () { > @Override > public void handleEvent (Event e) { > Rectangle rect = image.getBounds (); > int width = rect.width; > int height = rect.height; > GC gc = e.gc; > gc.setAntialias(SWT.ON); > int x = 10, y = 10; > int w = 0; > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 0.5), (int)Math.round(height * 0.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width, height); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.25), (int)Math.round(height * 1.25)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.5), (int)Math.round(height * 1.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width * 2, height * 2); > } > }); > > Canvas paintLow = new Canvas(parent, SWT.NONE); > paintLow.addListener (SWT.Paint, new Listener () { > @Override > public void handleEvent (Event e) { > Rectangle rect = image.getBounds (); > int width = rect.width; > int height = rect.height; > GC gc = e.gc; > gc.setAntialias(SWT.ON); > gc.setInterpolation(SWT.LOW); > int x = 10, y = 10; > int w = 0; > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 0.5), (int)Math.round(height * 0.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width, height); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.25), (int)Math.round(height * 1.25)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.5), (int)Math.round(height * 1.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width * 2, height * 2); > } > }); > > Canvas paintHigh = new Canvas(parent, SWT.NONE); > paintHigh.addListener (SWT.Paint, new Listener () { > @Override > public void handleEvent (Event e) { > Rectangle rect = image.getBounds (); > int width = rect.width; > int height = rect.height; > GC gc = e.gc; > gc.setAntialias(SWT.ON); > gc.setInterpolation(SWT.HIGH); > int x = 10, y = 10; > int w = 0; > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 0.5), (int)Math.round(height * 0.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width, height); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.25), (int)Math.round(height * 1.25)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = (int)Math.round(width * 1.5), (int)Math.round(height * 1.5)); > gc.drawImage (image, 0, 0, width, height, x += w, y, w = width * 2, height * 2); > } > }); > > Canvas paintTransform = new Canvas(parent, SWT.NONE); > paintTransform.addListener (SWT.Paint, new Listener () { > @Override > public void handleEvent (Event e) { > Rectangle rect = image.getBounds (); > int width = rect.width; > int height = rect.height; > GC gc = e.gc; >// gc.setAntialias(SWT.ON); >// gc.setInterpolation(SWT.HIGH); > int x = 10, y = 10; > Transform transform = new Transform(display); > transform.scale(0.5f, 0.5f); > gc.setTransform(transform); > gc.drawImage (image, 0, 0, width, height, Math.round(x / 0.5f), Math.round(y / 0.5f), width, height); > x += Math.round(width * 0.5f); > transform.dispose(); > > gc.setTransform(null); > gc.drawImage (image, 0, 0, width, height, x, y, width, height); > x += width; > > transform = new Transform(display); > transform.scale(1.25f, 1.25f); > gc.setTransform(transform); > gc.drawImage (image, 0, 0, width, height, Math.round(x / 1.25f), Math.round(y / 1.25f), width, height); > x += Math.round(width * 1.25f); > transform.dispose(); > > transform = new Transform(display); > transform.scale(1.5f, 1.5f); > gc.setTransform(transform); > gc.drawImage (image, 0, 0, width, height, Math.round(x / 1.5f), Math.round(y / 1.5f), width, height); > x += Math.round(width * 1.5f); > transform.dispose(); > > transform = new Transform(display); > transform.scale(2f, 2f); > gc.setTransform(transform); > gc.drawImage (image, 0, 0, width, height, Math.round(x / 2f), Math.round(y / 2f), width, height); > x += Math.round(width * 2f); > transform.dispose(); > } > }); > } > > public static BufferedImage createResizedCopy(BufferedImage source, int destWidth, int destHeight) { > BufferedImage bicubic = new BufferedImage(destWidth, destHeight, source.getType()); > Graphics2D bg = bicubic.createGraphics(); > bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); > float sx = (float)destWidth / source.getWidth(); > float sy = (float)destHeight / source.getHeight(); > bg.scale(sx, sy); > bg.drawImage(source, 0, 0, null); > bg.dispose(); > return bicubic; > } > > public static BufferedImage createResizedCopy(java.awt.Image source, double scale) { > BufferedImage bicubic = new BufferedImage((int) (16*scale), (int) (16*scale), BufferedImage.TYPE_INT_RGB); > Graphics2D bg = bicubic.createGraphics(); > bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); > bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); > bg.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); > bg.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); > > bg.scale(scale, scale); > bg.drawImage(source, 0, 0, null); > bg.dispose(); > return bicubic; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 97506
:
259133
|
272986
| 272988 |
284302
|
284303
|
284304
|
284305
|
288472