Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Graphics - drawing on an image + zooming
SWT Graphics - drawing on an image + zooming [message #447000] Tue, 07 December 2004 15:36 Go to next message
exquisitus is currently offline exquisitusFriend
Messages: 211
Registered: July 2009
Senior Member
Hi,

I'm working on an application that allows the user to open and view and
image, zoom in, zoom out and scroll around. The "Basic Image Viewer"
tutorial was very helpful in getting to grips with the SWT canvas and Java2D
transforms.

However, I need to be able to draw on this image to mark a feature - e.g.
draw a ring around the mouth to mark that mouth. The co-ordinates of the
marking are stored but the sourceImage should not be permanently altered.
Now I need to be able to zoom in and perhaps mark a smaller area, and as I
zoom in on the image, all visible markings are enlarged, so they are also
being "zoomed". Similarly, if I decide to scroll to the top of the photo,
all markings have to move down as if they are part of the screenImage.

So far, I am only able to draw shapes to the canvas. When it comes to
zooming and scrolling, I really don't know how best to tackle this in SWT.
It is very inefficient to change the position of every stored marking when
the user zooms or scrolls, as the paint method that places these shapes on
screen is called countless times throughout a scroll, and complex
mathematics have to be applied each time to find the new position (also
needs to iterate through the entire array of markings each time).

My ideal solution was to have a transparent image that lies on top of the
photo. All markings are applied to this image, and are visible onscreen, as
well as being stored. It's size would be identical to the photo, so whenever
we zoom/scroll we simply do the same to this transparent image. Does anyone
know of this is possible in SWT?

I have read a lot of tutorials on this, and have tried different techniques,
but I'm at a loss as how to tackle this particular problem. If anyone can
offer any help at all, even a web link to some informative
tutorials/articles on this, I would be very grateful.

Thanks,

Colin
Re: SWT Graphics - drawing on an image + zooming [message #447003 is a reply to message #447000] Tue, 07 December 2004 16:49 Go to previous message
Eclipse UserFriend
Originally posted by: armin.roth.visana.ch

I applied the snippet for TableCursor for my application. See:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet96.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup

This example puts basically a Canvas above a Table and redirects all kind
of events towards the Table.

The benefit of it is that the cursor is in his own drawable area but due
to
the redirects forces the table to redraw the affected area, i.e. I draw red
rectangles around cells with invalid contents and simulate focusing of
the table cursor by drawing it in different manner.

About the zooming: create an ImageData out of a BufferedImage (which
contains
the original picture) and with the ImageData create an Image.
At the paintControl() event calculated the position and stretching of the
picture part and use...

e.gc.drawImage(image, x, y, width, height, dx1, dy1, dx2-dx1, dy2-dy1);

to draw a zooomed part of the picture to the composite. That code was
though still flashing, but did not use any drawing optimization (redrawing
only the affected area - it just did redraw always the whole composite).

Kind regard,

Armin Roth


exquisitus wrote:

> Hi,

> I'm working on an application that allows the user to open and view and
> image, zoom in, zoom out and scroll around. The "Basic Image Viewer"
> tutorial was very helpful in getting to grips with the SWT canvas and Java2D
> transforms.

> However, I need to be able to draw on this image to mark a feature - e.g.
> draw a ring around the mouth to mark that mouth. The co-ordinates of the
> marking are stored but the sourceImage should not be permanently altered.
> Now I need to be able to zoom in and perhaps mark a smaller area, and as I
> zoom in on the image, all visible markings are enlarged, so they are also
> being "zoomed". Similarly, if I decide to scroll to the top of the photo,
> all markings have to move down as if they are part of the screenImage.

> So far, I am only able to draw shapes to the canvas. When it comes to
> zooming and scrolling, I really don't know how best to tackle this in SWT.
> It is very inefficient to change the position of every stored marking when
> the user zooms or scrolls, as the paint method that places these shapes on
> screen is called countless times throughout a scroll, and complex
> mathematics have to be applied each time to find the new position (also
> needs to iterate through the entire array of markings each time).

> My ideal solution was to have a transparent image that lies on top of the
> photo. All markings are applied to this image, and are visible onscreen, as
> well as being stored. It's size would be identical to the photo, so whenever
> we zoom/scroll we simply do the same to this transparent image. Does anyone
> know of this is possible in SWT?

> I have read a lot of tutorials on this, and have tried different techniques,
> but I'm at a loss as how to tackle this particular problem. If anyone can
> offer any help at all, even a web link to some informative
> tutorials/articles on this, I would be very grateful.

> Thanks,

> Colin
Previous Topic:PocketPC: Loading images
Next Topic:ScrolledComposite scrolling versus Canvas scrolling
Goto Forum:
  


Current Time: Thu Oct 22 07:45:46 GMT 2020

Powered by FUDForum. Page generated in 0.02170 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top