| Summary: | [GK3][Cairo] Images created with external image handle (GdkPixmap* or cairo_surface_t*) can't be drawn using GC.drawImage() | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Alexander Mitin <Alexander.Mitin> | ||||||
| Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> | ||||||
| Status: | CLOSED WORKSFORME | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | CC: | clayberg, ericwill, markus.kell.r, Silenio_Quarti | ||||||
| Version: | 4.2 | Keywords: | triaged | ||||||
| Target Milestone: | --- | ||||||||
| Hardware: | PC | ||||||||
| OS: | Linux-GTK | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
Created attachment 217112 [details]
Incorrectly drawn image.
Created attachment 217113 [details]
Image drawn using getImageData() workaround, correctly drawn.
+1 Fixed http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=572d213ab35a497c10eab2f88d0a1f11c36bb71c Simple test: import org.eclipse.swt.graphics.Image; import org.eclipse.swt.internal.gtk.GdkColor; import org.eclipse.swt.internal.gtk.OS; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class Test { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(1, false)); long pixmap = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), 100, 100, -1); GdkColor white = new GdkColor(); white.red = (short)0xFFFF; white.green = (short)0; white.blue = (short)0; int /*long*/ colormap = OS.gdk_colormap_get_system(); OS.gdk_colormap_alloc_color(colormap, white, true, true); int /*long*/ gdkGC = OS.gdk_gc_new(pixmap); OS.gdk_gc_set_foreground(gdkGC, white); OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, 100, 100); OS.g_object_unref(gdkGC); OS.gdk_colormap_free_colors(colormap, white, 1); final Image image = Image.gtk_new(null, SWT.BITMAP, pixmap, 0); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { event.gc.drawImage(image, 10, 10); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } Reopening this.
While using gtk3 if I create an Image instance with external Cairo surface handle at least the following don't work:
1. Image.getBounds() returns Rectangle of (0, 0, 0, 0).
2. gc.drawImage(image, 0, 0) does nothing.
It seems to me the problem is that width/height fields are not initialized.
The workaround is to use Image(Device device, ImageData data) constructor:
Image image = Image.gtk_new(null, SWT.BITMAP, surfaceHandle, 0);
Image newImage = new Image(null, image.getImageData());
image.dispose();
Is this still reproducible? (In reply to Eric Williams from comment #6) > Is this still reproducible? No response in awhile -- closing. Please reopen this ticket if the issue occurs on 4.8 with GTK3.22. |
In WindowBuilder project I have to create an Image instance using external GdkPixmap* value. I used Image.gtk_new() method to create such Image. Then I need to draw this image on some GC. This works fine with Cairo disabled. When Cairo is enabled, the image is not drawn. The workaround is to invoke Image.getImageData() method. After this invocation it works fine. Sample code: Image image = Image.gtk_new(null, SWT.BITMAP, pixmapHandle, 0); Image mainImage = new Image(null, 240, 160); GC gc = new GC(mainImage); // image.getImageData(); // uncomment to get it working gc.drawImage(image, 0, 0); gc.dispose(); // save mainImage using ImageLoader