Scale Annotations to be proporational for any image res.

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

Moderator: Alex

Post Reply
average_male
Posts: 3
Joined: Tue May 29, 2012 9:14 pm

Scale Annotations to be proporational for any image res.

Post by average_male »

Hello Alex,

1) How can we determine the bounding box for a text annotation given a loaded arbitrary image?
2) How can we get the Graphics class associated with a loaded arbitrary image?

Both of the questions above are aimed to achieve the same goal: How to scale your annotations such they they appear to be the same size(height/width) relative to any loaded image with a given resoltion/size.

When adding annotations to our images via an off-line process (process that requires no user intervention), we would like to determine the required size of the bounding box for a given string for a given image resolution such that we can render text proportionally to the size/resolution of the source image. The end result is we want the annotation to be the same size relative to the source image. Example: We want the word "Test" to be take up a quarter of the image's width where the height of the text can vary to accomidate for this.

To determine the text boudning box GDI/MFC we simply use CDC.GetTextExtent() passing in the string and we get the CSize class that bounds the text for the CDC. From here we can increase the Font size to get the desired text scaling and recheck the bounding box. There may be an easier way, if so, I'd be interested in hearing how that can be done.

Also, seems the SDK for Vintasoft has incorrectly named the "GetGraphics()" operation for the VintasoftImage class.

Code: Select all

Graphics g = image.GetGraphics();
This operation should be called, "CreateGraphics" as the GetGraphics does exactly that (as the intellesense notes states); I was hoping I could Get the current graphics associated with Vintasoft image and perhaps use the "MeasureString()" operator for the given Graphics class.

Thanks,
Moe
average_male
Posts: 3
Joined: Tue May 29, 2012 9:14 pm

Re: Scale Annotations to be proporational for any image res.

Post by average_male »

Found a partial solution with the use of the "Font.FontSizeDependsImageResolution" attribute to get the bounding rectangle height once the font size and style is specified:

Code: Select all

TextAnnotation header = new TextAnnotation();
 header.Text = "Test";
 header.FontSizeDependsImageResolution = true;
 header.Font = new Font("Arial Black", 50.0f);
 float boundingBoxHeight = header.Font.Height;  
 float boundingBoxWidth = <???>;   //How do I get the Width of the Text for the current font and loaded image?
If I can get a handle to the image's Graphics class, I could then do a Graphics.MeasureString() against the font/text. How can this be done?

Any imput would be greatly appreciated,
Moe

PS- The 'Font.TextPadding' property says its a Get/Set, but when I try to set it, compiler states its not a variable. Why is that?
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Scale Annotations to be proporational for any image res.

Post by Alex »

Hello Moe,
How can we get the Graphics class associated with a loaded arbitrary image?
You can use the GetGraphics method of the VintasoftImage class.

Found a partial solution with the use of the "Font.FontSizeDependsImageResolution" attribute to get the bounding rectangle height once the font size and style is specified...
Yes, the FontSizeDependsImageResolution property of the TextAnnotation class allows that font size must be scaled depending of image resolution.

Font size scaled using following formula: font_size = font_size * 96 / image_resolution.


Do you have any problems at the moment?

Best regards, Alexander
Post Reply