Small problem: In order to improve the perf of a given map, I need to create layers ... In Swing, no problem: we have the JLayeredPane SWT ... but that neni!

So here's a little trick to create transparent images (the background maps have generally need to be calculated only once!)

  1. / / Set the color that will be considered transparent
  2. ( ) . getSystemColor ( SWT. COLOR_WHITE ) ; LTransparentColor = Color Display. GetDisplay (). GetSystemColor (SWT. color_white);
  3. / / Create a palette with transparent color and all other
  4. / / Necessary color to the image (here lOtherColor)
  5. new RGB [ ] { PaletteData lPalette PaletteData = new (new RGB [] (
  6. , lTransparentColor. getRGB ()
  7. lOtherColor. getRGB ()
  8. ));
  9. / / Create the image with the palette
  10. lWidth, lHeight, 2 , lPalette ) ; LImageData ImageData = new ImageData (lWidth, lHeight, 2, lPalette);
  11. / / Set the transparent color of the image (white here)
  12. ( lTransparentColor. getRGB ( ) ) ; lImageData. transparentPixel = lPalette. getPixel (lTransparentColor. getRGB ());
  13. / / And now!
  14. ( lDisplay, lImageData ) ; filing = new Image (lDisplay, lImageData);
  15. ( ) ; Rectangle = lImageBounds filing. GetBounds ();
  16. / / The GC will draw in the image
  17. lImage ) ; GC LGC = new GC (filing);
  18. / / First step: complete the picture of a completely transparent background
  19. lTransparentColor ) ; LGC. setbackground (lTransparentColor);
  20. lImageBounds ) ; LGC. FillRectangle (lImageBounds);
  21. / / And now remains is to draw as before in the GC!

This is a first step towards drawing in layers ... I will return later with a small lib ...

Related Articles