Re: Himetric...yuck

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Mike D Sutton (EDais_at_mvps.org)
Date: 10/07/04


Date: Thu, 7 Oct 2004 23:48:05 +0100


> When using EMF files, when I create my DC, I am specifying a rectangle, and this
> rectangle needs to be in Himetric units. Or am I wrong? I actually build a
> RECT structure and populate it with the size of rectangle in pixels I'll need
> (0,0,100,100), then I call the ScaleX/ScaleY methods of my form to convert the
> right and bottom to himetric units.

This is fine, if you want an alternative method to get away from relying on VB's objects then have a look at the OLEPicture library
on my site which contains conversion routines between Pixels and Himetric. You could also use an IC (or DC if you have one
available) with MM_HIMETRIC mapping mode set and the DPtoLP() call to convert from device space (pixels) to logical coordinate space
on the I/DC (himetric), however GDI's himetric units have a negative Y axis so you'll need to negate either the input or output Y
coordinate.

> Interestingly enough, when I use API Draw functions, I can use pixels still. I
> really don't understand why.

The rectangle given to the EMF creation routine simply defines the size of the 'canvas' you wish to create (note; if you don't
specify an area here then GDI will track the largest extents of your drawing and use that as the area when you close the MetaDC), it
bears no relation to the mapping mode of the MetaDC() to get given back. If you call GetMapMode() on the MetaDC() you'll find that
it return the default of MM_TEXT which happens to map 1:1 to device space and thus pixels. You could very well set MM_HIMETRIC
mapping mode on your MetaDC if you prefer to use himetric units in your drawing calls.

> Finally, when playing the EMF file into another Device Context (a bitmap DC, not
> an EMF DC, if there is a difference), I have to tell it a rectangle to play
> into. Interestingly enough, again I have to specify the coords in Himetric
> units and not pixels. And this time, ScaleX/ScaleY do not return the correct
> values. I had to create a function that uses the GetDeviceCaps function,
> passing in the current DC, and figure out what the conversion factor should be.
> I really don't understand why again.

Hmm, sounds to me like the device context you're playing into has a different mapping mode set, you'll need to use DPtoLP() to
convert the coordinates you wish to render at in pixels to it's local drawing units - PlayEnhMetaFile()'s lpRect structure is
defined in logical units on the target device context.

> So, first, is there any way to make EMF files work in pixels only? I would
> guess not, since they are vector based things, but if it is holding onto a
> distinct measurement of 1/100 of a mm, why can't it just use pixels?!?

Hopefully the above helped sort some of this out for you, you may want to have a look through the mapping modes section of the DC
tutorial on my page which goes though some of this and gives you example code to work with. As far as your query goes, you have no
choice but to specify the EMF area in himetric units when it's created but everything after that is in logical coordinate space
which can be set with the SetMapMode() API call.

> Second, why would ScaleX/Y from Pixels to Himetric work correctly, but not the
> converse?

My guess would be that the DC you're rendering to does not have it's logical coordinate space set to himetric units, again though by
using the logical/device space conversion routines you can convert between pixels and logical space as you wish.

> I've actually got this code "working" but if anyone has any pointers for me, I'd
> love to hear them.

Hope some of the above made sense!

    Mike

 - Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: http://EDais.mvps.org/



Relevant Pages

  • Himetric...yuck
    ... When using EMF files, when I create my DC, I am specifying a rectangle, and this ... rectangle needs to be in Himetric units. ... Interestingly enough, when I use API Draw functions, I can use pixels still. ... So, first, is there any way to make EMF files work in pixels only? ...
    (microsoft.public.vb.winapi.graphics)
  • Re: Picture.Width
    ... width come back as 26.5 times the actual width of the bitmap? ... There are 100 HiMetric units in a millimeter. ... The original conversion from pixels into HiMetric units is done in accordance with the "dots per inch" setting of the machine on which your code is running, so you can convertback to pixels using: ...
    (microsoft.public.vb.general.discussion)