See below
-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM] On Behalf Of
Peter Ritchie
Sent: Wednesday, August 02, 2006 9:48 AM
To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] Bitmaps and DPIs
Andrew, in 15+ years of Windows programming I can count on
one hand the
number of times DPI was an issue with on-screen bitmaps.
99.9% of the time it's 96dpi. Historically, everything
looks like crap
in
Windows if you change that. I actually encountered a
program that
simply
wouldn't run if the DPI wasn't 96, it said it didn't
support that DPI
and
simply exited--don't do that. Vista may introduce
improvements to this
(I
doubt the problem will go away though)...
[Andrew] This isn't as true as it used to be. Newer
machines these days
tend to have larger monitors and many of them come preset to
run at
120dpi - my new laptop did. Also I believe that some OSes
(Korean XP
comes to mind) also tend to default to a larger dpi than 96
Technically the user can select whatever DPI they want with
most video
drivers. You could have a set of canned DPIs then scale the
others.
[Andrew] That's my option 3
I've never encountered an issue where the bitmap size
needed to be
anything other than pixel width/height, i.e. not inch
width/height.
e.g.
users don't expect a window to be 5 inches by 10 inches on
all monitors,
they expect it to be 480 x 960 on all monitors, appearing
increasing
smaller as resolution increases.
The DPI-changing abilities in Windows is why some
applications have the
concept of small and large buttons. If the DPI is
sufficiently low for
a
given installation the user can choose to increase the size
of the
buttons
to use larger bitmaps (some application simply scale the
bitmaps,
defeating the intention of larger buttons, IMO). But again,
the
actually
DPI is somewhat irrelevant...
And that's what WinForms sort of assumes you're doing. By
default
scaling
is in DPI mode.
[Andrew] Not true any more. The default scaling is
AutoScaleMode.Font
which is subtly different It's actually pretty tricky to
make sure a
Windows Forms application behaves correctly at arbitrary
dpis and there
are some .NET bugs in this area - but that's a whole other
discussion.
If the user changes DPI the whole form is scaled. If you
then used a different (essentially larger dpi) bitmap it
would be too
large to fit with the rest of the form.
[Andrew] Well that really depends on whether the bitmap
scales as you
change dpi which was the point of my question. For instance
if the
background image of my form is a bitmap, when I run my form
at 120 dpi
(with AutoScaleMode.dpi), the contents of the bitmap look
smaller
relative to the rest of the application - I can either live
with that or
use a larger background image at 120 dpi.
The DPI difference is usually
negligible, not real worth the effort of overriding
WinForm's default
behaviour just to get a UI element to show up at a specific
inch width &
height. e.g. going to "large fonts" is usually
just a 25% increase.
Usually users change this to get more screen real estate, if
you scale
everything up for the new DPI they won't get that.
[Andrew] I don't follow this. There is a factor of 2
difference between
96 dpi and 192 dpi (which is not a totally unreasonable dpi)
At 192 dpi
do I want to see bitmaps that are half the size or scaled? -
probably
neither of the above
What is usually the issue is printing bitmaps. Going from a
bitmap on
screen at 96dpi to a printer at 300dpi, 600dpi, and
sometimes 1200dpi
(although that's usually extrapolated). If you want to
print these
bitmaps, you'll definitely want either dpi-native bitmaps
or have one
scaled down to all the other dpis.
-- Peter
Microsoft MVP, Visual Developer - Visual C#
http://www.peterRit
chie.com/blog/
On Wed, 2 Aug 2006 09:18:55 -0400, Andrew Eames
<andrew COGNEX.COM>
wrote:
>Hi,
> I am building a very fancy custom user interface for a
new product
and
>we are utilizing a graphic designer to make some cool
bitmaps for us. I
am
>wrestling a little bit with how to handle these bitmap
graphics while
at
>the same time supporting multiple (arbitrary) dpi
settings.
>
>For most custom graphics my preference is to draw them
programmatically
>since that way I can scale them arbitrarily but when
this is not
possible
>and I have to use bitmaps it seems like I have 3
options.
>
>1) Use the same bitmap at all dpis
> Pro: easy to do Con: Bitmaps are wrong size at some
dpis
>
>2) Use the same bitmap at all dpis but scale it
dynamically
> Moderately easy to do Con: Scaled bitmaps dont look
great
>
>3) Create a variety of bitmaps at different dpis (which
ones???) and at
>runtime pick the closest one to the current dpi
> Pro: Looks pretty good Con: Much more work for graphic
designer, more
>programming required
>
>I can't be the first to figure out the best course of
action although I
>suspect most peple just default to 1). Does anyone have
any useful
>opinions?
|