?
Solved

Font scaling between image resolutions.

Posted on 2008-06-18
4
Medium Priority
?
747 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 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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