Hi

Re-reading my first response, I think it's a bit elliptical, so I'll try to
be more lucid this time. I'm assuming that the main aim is to render the map
data accurately on the screen, and you want to set up a user coordinate
system such that, say, 100 units is exactly 1cm on the real screen. There
are two ways of doing this, one involving changing the Windows settings (I'm
still assuming that's the platform), and one that doesn't.

To do the first method, measure the width of the active areas of the screen.
It's 308mm on my 17" monitor. Divide the screen X size by that to get the
pixels per millimetre - in my case it's 1024/308, or 3.32. Multiply by 25.4
to get pixels per inch, which is 84.4. (OK, you could have gone straight to
inches, but you're in Canada...) This is the number you need to set in the
Windows Display settings so that Windows' idea of a pixel is the same size
as your monitor's. As I implied earlier, Window uses this mainly to scale
fonts to roughly the right size, and also for its own graphics
transformations.

After you do this and reboot your machine, reading the resolution from
Java2D will give you 84 (Windows doesn't allow fractional values). Now
Java2D still thinks there are 72 pixels per inch regardless, so before
plotting anything, you'd want to scale the transform by the resolution/72.0f
factor I mentioned before. At this point, 1 user unit corresponds to 1pt
(1/72") on the screen. To get, say 100 units/cm (which is 254 units/inch,
you would scale further by 254/72.0 = 3.53f).

The other approach is to leave the Windows setting at its default value of
96 ppi, and do all of the scaling in Java. The advantage of this is that
your Windows fonts will probably look better than if you changed the
settings, and it will break less software. So first you need to map from
Windows' notional resolution to the actual ppi of 84.4. Do this by setting
the scale to 84.4/resolution. Next, apply the resolution/72 scaling we did
before. This gets you to 72pixels/ screen inch. Of course, the "resolution"s
cancel out, you you're left with 84.4/72. This make sense, because the only
reason we were using the Windows resolution in the first case was to get the
physical PPI of the monitor into the system. If you can get it another way
(e.g. through a properties file that you read at start-up), you can safely
ignore it. (This method also lets you set it to a float instead of being
constrained to Windows' ints.) Finally you apply whatever user-coordinate
transformation you want.

Hope this helps,
Cheers,
Pete


----- Original Message -----
From: John Sproull <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: June 11, 1999 5:50 AM
Subject: [java2d] getScreenResolution


>
>  Hi, all.. this may have been dealt with before, so forgive me if you've
> heard this.. I'm trying to get the screenresolution (in dpi) of the
> current user's screen. We're working with map information so converting
> milimeters in the map to a proper mapping scale is tough when
> getScreenResolution() always returns 96. :) here's what i'm using:
>
> Toolkit defaultToolKit = Toolkit.getDefaultToolkit();
> int resolution = defaultToolKit.getScreenResolution();
>
>  anyone know a solution to this? thanks!
>
>  John Sproull
>  Universal Systems, Ltd.
>  Fredericton, NB
>
>
> =====================================================================
> To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
> Java 2D Home Page: http://java.sun.com/products/java-media/2D/
>

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/

Reply via email to