-
Notifications
You must be signed in to change notification settings - Fork 52
Closed
Description
With a display set to 200% scaling on Windows calling GC.drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) when using a FileImageDataProvider can cause an IllegalArgumentException.
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FileImageDataProviderIllegalArgumentException {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(800, 600);
Image image = FileImageDataProvider.createImage(FileImageDataProviderIllegalArgumentException.class, "GEF.svg");
int width = image.getBounds().width;
int height = image.getBounds().height;
shell.addPaintListener(event -> {
GC gc = event.gc;
gc.drawImage(image, 0, 0, width, height, 0, 0, width, height);
});
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) {
display.sleep();
}
}
}
}Use this SVG image with the Snippet:
See eclipse-platform/eclipse.platform.swt#2916
FileImageDataProvider.getImageData() should really return null for zoom 200 and FileImageDataProvider.createImageData() should check for null InputStream:
@Override
public ImageData getImageData(int zoom) {
if (zoom == 100) { //$NON-NLS-1$
return createImageData(basePath + '.' + fileExtension);
}
if (zoom == 200) {
return createImageData(basePath + "@2x." + fileExtension); //$NON-NLS-1$
}
return null;
}
private ImageData createImageData(String name) {
try (InputStream stream = clazz.getResourceAsStream(name)) {
return stream != null ? new ImageData(stream) : null;
} catch (IOException ioe) {
return null;
}
}Metadata
Metadata
Assignees
Labels
No labels