Graphics.DrawString inconsistent drawing behavior on Dell Axim x50v (640x480)

Graphics.DrawString inconsistent drawing behavior on Dell Axim x50v (640x480)

Post by holmer » Fri, 29 Dec 2006 05:48:05


We have code that creates a Bitmap object and uses the Graphics object
derived from it to draw string data on that Bitmap. When we execute
that code on on the Full Framework, or on the compact framework listed
below on a 240x320 device, the bitmaps produced are identical. When we
run that same code on a Hi-Dpi device, the text is drawn much larger
with respect the the bitmap. I am assuming that the Lo-Dpi device is
drawing correctly because it matches the output of the full framework.

Has anyone else encountered this issue, and is there a workaround other
than P/Invoking GetDeviceCaps and switching between a set of Hi-Dpi
code and another set of Lo-Dpi Code?

Test Devices = Dell Axim x50 (240x320) and Dell Axim x50v (480x640)
OS = Win Mobile 2003 SE
CF = 2.0 SP1 (2.0.6129.0)

TIA,
John
 
 
 

Graphics.DrawString inconsistent drawing behavior on Dell Axim x50v (640x480)

Post by » Fri, 29 Dec 2006 06:03:28

Why not have the code query the screen size (Screen.PrimaryScreen.Bounds) on
which it is running and calculate the font size based on that? No need to
P/Invoke, and the code will then work for all resolutions.

-Chris

 
 
 

Graphics.DrawString inconsistent drawing behavior on Dell Axim x50v (640x480)

Post by holmer » Sat, 30 Dec 2006 04:11:12

Thank you for your reply.

Because I wasn't drawing on-screen I looked at the DpiY property of the
Graphics object I was drawing with to basically determine which device
type I was drawing on -- thanks for alerting me to non P/Invoke ways to
get that -- it saved my unit test.

I noticed that the DPI on my Hi-Res device was 192 and for the Lo-Res
was 96. That handily explained why my Hi-Res was drawing twice as
large as the other device. I am not drawing the image to a PDA screen,
but writing a bitmap that I will save to disk and send to our server,
so I switched to the Font.FromLogFont method call to create my font
object and hardcoded 96 as my DPI value for consistent bahavior (would
like to hear your opinion on that).

So currently I am drawing with a 12 point Arial font that is looking
fairly pixelated on my screen. Do you have any suggestion to have the
font draw more smoothly?


public static Font GetFont(int size, string name, LogFontWeight weight,
bool italic,
bool underline, bool strikeout, LogFontQuality quality )
{
LogFont lf = new LogFont();
lf.CharSet = LogFontCharSet.Default;
lf.OutPrecision = LogFontPrecision.Default;
lf.FaceName = name;
lf.Underline = (byte) ( underline ? 1 : 0 );
lf.StrikeOut = (byte) ( strikeout ? 1 : 0 );
lf.Italic = (byte) ( italic ? 1 : 0 );
lf.Weight = weight;
lf.Quality = quality;

lf.Height = (int)( -1 * ( size * 96 / CUR_DPI ) );

return Font.FromLogFont( lf );
}

With calling values of:
regFont = FontFactory.GetFont(12, "Arial", LogFontWeight.Normal, false,
false,
false, LogFontQuality.ClearType );
boldFont = FontFactory.GetFont(12, "Arial", LogFontWeight.Bold, false,
false,
false, LogFontQuality.ClearType );

Thanks again,
John