• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 748
  • Last Modified:

Font scaling between image resolutions.

Hi All,

I've been tinkering with this for a while now and I think my brain has finally melted so hopefully somebody can help clear things up for me.

I have a photo app that manipulates images that are 2540x1778 @ 254ppi. For obvious reasons, when manipulating the image in the application we use a scaled down version (currently 500x349 @ 96ppi). The trouble I am currently having is upscaling text from the smaller image back to the full size image when it comes to saving, particularly taking into account the difference in resolutions.

Hopefully somebody can make this simple for me, or at least point me in the right direction.
0
Carl Tawn
Asked:
Carl Tawn
  • 2
  • 2
1 Solution
 
Bruce_1975Commented:
Hi Carl,
The position of the text is not affected by the resolution. You just have to scale it by the size of the image.
The size of the text is affected by the scale. So you have to scale the size of the used font. I have not tested the snipped but it should work.

Regards,
Bruce
private void DrawString(Graphics G, int PreviewResolution, int OriginalResolution, Font TextFont, string Text, Brush TextBrush, PointF Position)
{
    float scale = (float)OriginalResolution / (float)PreviewResolution;
    Font font = new Font(TextFont.Name, TextFont.Size * scale);
    G.DrawString(Text, font, TextBrush, Position);
}

Open in new window

0
 
Carl TawnSystems and Integration DeveloperAuthor Commented:
Hi Bruce,

Thanks for your reply. I'm already doing something pretty much the same as that, but its not 100% right, the up-scaled text is slightly off and I can't quite suss out why. I am currently using a transparent label for the text (probably not the best way as its a bit flickery, any ideas on a better method would be handy!) so i'm not sure if i'm just confusing myself when it comes to which values (i.e. label size/clientsize or text length) i'm supposed to be using as the basis of the scaling.

The label and, from the looks of it DrawString(), seem to force a slight margin between where the text actually sits in relation to the point where I tell it to draw. Maybe this is throwing off my calculations too.
0
 
Bruce_1975Commented:
I can't see the discribed behavior if I draw it directly to the image.
May be I this is caused by the smaller image I used or there is an issue with the transparent label (Text offset depending on the size or something like that.)

... I played around with Graphics.DrawString and Label... they have different draw methods for the same font. The scaling between images goes right but there is a slight difference in line thickness and character with.
Because of this I think the drawing method of the label is the problem and you have to draw the string with Graphics :o(

Regards,
Bruce

BTW:  change the scaling in the snipped to
float scale = (float)PreviewResolution / (float)OriginalResolution;
0
 
Carl TawnSystems and Integration DeveloperAuthor Commented:
Finally its working!! I switched from using a label to a picturebox with the text drawn in it so that it would render the same on both the preview and full size image. I had to do a little bit of tinkering with the StringFormat object to get it to play ball, but at least its sorted now.

Thanks for the help Bruce, much appreciated.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now