Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] Draw RenderedImage

Hello and happy new year to all




Le 4 janv. 06 à 11:32, Iñigo Telleria Elola a écrit :

I want to draw an RenderedImage (obtained from udig's map) in a SWT shell. I have tried differents possibilties:

1) with GC, but this object doesn't have any method to draw RenderedImage (only Image).
2) with SWTGraphics, It doesn't work.
3) with Graphics2D, I don't know how to use.

anybody has an idea how I can achieve?

Thanks in advance
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel



here some (very partial)code i am using into an SWT Canvas :

public class ImageCanvas extends Canvas implements MouseListener, MouseMoveListener{
private Composite parent;
 private Shell dialog;
 private PaintEvent curevent=null;
private Listener resizeListener=null;
 private PaintListener paintListener=null;
private Dimension displaySize = new Dimension(20, 20);
private Rectangle curclientArea;
 private RenderedImage imageToDraw=null;



public ImageCanvas(Shell dialog, Composite parent)
    {
        this(dialog,parent,0);

    }
    public ImageCanvas(Shell dialog, Composite parent, int style ) {
        super(parent, style);
    try{
        resizeListener = new Listener(){
            public void handleEvent( Event event ) {
                Point size = getSize();

displaySize = new Dimension(Math.min(size.x, size.y),Math.min(size.x, size.y)); // i want a square)

            }
        };
        addListener(SWT.Resize, resizeListener);

    this.parent=parent;
    this.dialog=dialog;

    paintListener = new PaintListener()

    {

      public void paintControl(PaintEvent event)

      {
          curevent=event;
          curclientArea = getClientArea();
         onPaint(event);


      }

    };
    addPaintListener(paintListener);

    }catch(Exception e)
    {
        e.printStackTrace();
    }


}


public Dimension getDisplaySize() {
        return displaySize;
    }

    public void setDisplaySize(int width,int height) {
        displaySize = new Dimension(width, height);
        dialog.redraw();
        dialog.update();

    }
    /**
     * @see net.refractions.udig.project.render.MapDisplay#getWidth()
     */
    public int getWidth() {
        return getDisplaySize().width;
    }

    /**
     * @see net.refractions.udig.project.render.MapDisplay#getHeight()
     */
    public int getHeight() {
        return getDisplaySize().height;
    }


protected void onPaint(final PaintEvent event)
{

      final Display display = event.display;

    final GC gc = event.gc;

    final Rectangle rect = curclientArea;


    if (rect.width == 0 || rect.height == 0) return;

final SWTGraphics swtGraphics = new SWTGraphics(gc, display, getDisplaySize());



    if (imageToDraw != null)
    {
swtGraphics.drawImage(imageToDraw, 0, 0, getWidth(), getHeight(), 0, 0, param.cols, param.filas);





    }
      swtGraphics.dispose();
    /*
         */
         System.out.println("onPaint done");







}

hope this help !

Jacques Divol
Ingénieur de Recherche temp Unité Espace-IRD
@mail :jacques.divol@xxxxxxxxxxxxxxxx





Back to the top