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
Annotation location on an image
Moderator: Alex
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: Annotation location on an image
Hello Andrew,
Do you want to add annotation programmatically or visually? Why don't you use standard methods?
Best regards, Alexander
Do you want to add annotation programmatically or visually? Why don't you use standard methods?
Best regards, Alexander
-
- Posts: 2
- Joined: Fri May 08, 2009 11:17 am
Re: Annotation location on an image
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
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
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: Annotation location on an image
Hello Andrew,
Best regards, Alexander
Please read the "Getting Started" topic in the VintaSoftAnnotation.NET Plug-in section of documentation.I looked at your Annotation demo where they are added visually but the size of the annotation is always zero...
AnnotationBase class has the Size property - use it to change annotation size. Also please read the documentation!I can set colour but not size...
You can set the AnnotationViewer.SelectionMode property to the SelectionMode.Tool value and users will be not able to change annotations.I also don't want users to be able to re-size or rotate...
Best regards, Alexander
-
- Posts: 14
- Joined: Fri Apr 24, 2009 1:45 am
Re: Annotation location on an image
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:
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
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