Solved

Font scaling between image resolutions.

Posted on 2008-06-18
4
744 Views
Last Modified: 2013-12-16
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
Comment
Question by:Carl Tawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:Bruce_1975
ID: 21812417
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
 
LVL 52

Author Comment

by:Carl Tawn
ID: 21812659
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
 
LVL 6

Accepted Solution

by:
Bruce_1975 earned 500 total points
ID: 21813031
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
 
LVL 52

Author Comment

by:Carl Tawn
ID: 21822088
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question