Annotation location on an image

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
andrewd
Posts: 2
Joined: Fri May 08, 2009 11:17 am

Annotation location on an image

Post by andrewd »

Hi,
I'd like to add an annotation to an image by double-clicking it but I can't work out how to calculate the correct location on the image.
The mouse.x and mouse.y locations are relative to the viewer not the image.
If the image in centered in the viewer clicking on say the top right hand corner might give mouse.x=200 and mouse.y=0 but the correct location to display the annotation is 0,0.
Thanks, Andrew
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Annotation location on an image

Post by Alex »

Hello Andrew,

Do you want to add annotation programmatically or visually? Why don't you use standard methods?

Best regards, Alexander
andrewd
Posts: 2
Joined: Fri May 08, 2009 11:17 am

Re: Annotation location on an image

Post by andrewd »

Hi Alex,
I looked at your Annotation demo where they are added visually but the size of the annotation is always zero. I can set colour but not size when it's done visually. I also don't want users to be able to re-size or rotate but I want to add a context menu.
Andrew
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Annotation location on an image

Post by Alex »

Hello Andrew,
I looked at your Annotation demo where they are added visually but the size of the annotation is always zero...
Please read the "Getting Started" topic in the VintaSoftAnnotation.NET Plug-in section of documentation.
I can set colour but not size...
AnnotationBase class has the Size property - use it to change annotation size. Also please read the documentation!
I also don't want users to be able to re-size or rotate...
You can set the AnnotationViewer.SelectionMode property to the SelectionMode.Tool value and users will be not able to change annotations.

Best regards, Alexander
ltiong
Posts: 14
Joined: Fri Apr 24, 2009 1:45 am

Re: Annotation location on an image

Post by ltiong »

Hey Andrew,

If you you're still looking to drop annotations on an image w/ the double-click (ie determine the coordinates of the top left corner of the displayed Image), you can try something like:

Code: Select all

            // get a hold of the Image being displayed
            VintasoftImage vi = annotationViewer1.Images[annotationViewer1.FocusedIndex];

            // determine widths of canvas and image.
            int av_width = annotationViewer1.ClientSize.Width;
            int av_height = annotationViewer1.ClientSize.Height;
            int im_width = vi.Width;
            int im_height = vi.Height;

            // calculate Image offset
            int x0 = (av_width > im_width ? (av_width - im_width) / 2 : 0);
            int y0 = (av_height > im_height ? (av_height - im_height) / 2 : 0);

            // get your mouse Point
            Point mp = annotationViewer1.PointToClient(Control.MousePosition);

            // get the translated location
            Point annotationLocation = new PointF(mp.X - x0, mp.Y - y0);

Note: This is the basic concept. It'll drop an annotation centered on your double-click. There are other things you may want to take into consideration such as the Margin/Padding on the AnnotationViewer object.

Lu
Post Reply