Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rescaling metafile... problems with DC size.

66 views
Skip to first unread message

juan

unread,
Jan 8, 2007, 10:34:16 AM1/8/07
to
Hi!
I want to rescale a metafile to a bigger dimension....
So this is what I do:
BOOL bRes = OpenClipboard(NULL);
HDC hdc = GetDC(NULL);
if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) {
HENHMETAFILE hEmf = (HENHMETAFILE )GetClipboardData(CF_ENHMETAFILE);
HDC hMetaFileDC;
ENHMETAHEADER emhHeader;
GetEnhMetaFileHeader(hEmf,sizeof(ENHMETAHEADER),&emhHeader);
RECT newRect;
newRect.left = emhHeader.rclFrame.left;
newRect.right = (g_MetaFileRect.right *
emhHeader.rclFrame.right)/emhHeader.rclBounds.right;
newRect.top = emhHeader.rclFrame.top;
newRect.bottom = (g_MetaFileRect.bottom *
emhHeader.rclFrame.bottom)/emhHeader.rclBounds.bottom;
newRect.bottom-=100;
newRect.right-=100;
hMetaFileDC=CreateEnhMetaFile(hdc,"c:\\new.emf",&newRect,"MyApp\0MyDesc\0\0");
if( hMetaFileDC ) {
PlayEnhMetaFile(hMetaFileDC,hEmf,(CONST RECT *)&g_MetaFileRect);
HENHMETAFILE nNewMetaFile = CloseEnhMetaFile(hMetaFileDC);
}
}
ReleaseDC(NULL,hdc);
CloseClipboard() ;

As you can see, I save the clipboard content as c:\new.emf but this
c:\new.emf is bigger (depending on the g_MetaFileRect);

Let me use an example to explain the problem: Suppose I copy from Word
an entire page and the resulting page is 1000 x 1000 pixels (so
g_MEtaFileRect is 0,0,1000,1000).
Now suppose that my monitor (Device context) is 800 x 600.

When I make the PlayEnhMEtaFile, if at the bottom of the metafile (e.g.
coordinate 900,900) there is a graphic, then the c:\new.emf does not
draw this image.

I discovered that PlayEnhMetaFile has a limit... if inside the metafile
there is a EMR_STRETCHDIBITS record, if the coordinates are bigger than
the screen resolution then it does not work.
I confirm it by enumerating the records of the original metafile
against the generated one and this EMR_STRETCHDIBITS record is missing.

How can I resize the metafile? Is there any way to bypass this limit?

Thanks

Michael Phillips, Jr.

unread,
Jan 8, 2007, 1:01:31 PM1/8/07
to
The RECT specified in CreateEnhMetafile must be dimensioned in
.01-millimeter units.

In your code, it is not clear you are using dimensions specified as above.

If all you want is to create a bitmap that looks exactly like the metafile
when played back against a DC, then the code that I provided in my previous
post will do the job.

The Enhanced metafile will scale to any DC it is played to. If you wish to
scale the metafile to dimensions other than what was originally recorded,
then convert the metafile to a bitmap and rescale the bitmap to the
dimensions that you need.

"juan" <juan_r...@hotmail.com> wrote in message
news:1168270456.4...@51g2000cwl.googlegroups.com...

Ben Voigt

unread,
Jan 17, 2007, 1:41:55 PM1/17/07
to

"Michael Phillips, Jr." <mphil...@nospam.jun0.c0m> wrote in message
news:%23Ok%23C80MH...@TK2MSFTNGP03.phx.gbl...

> The RECT specified in CreateEnhMetafile must be dimensioned in
> .01-millimeter units.
>
> In your code, it is not clear you are using dimensions specified as above.
>
> If all you want is to create a bitmap that looks exactly like the metafile
> when played back against a DC, then the code that I provided in my
> previous post will do the job.
>
> The Enhanced metafile will scale to any DC it is played to. If you wish
> to scale the metafile to dimensions other than what was originally
> recorded, then convert the metafile to a bitmap and rescale the bitmap to
> the dimensions that you need.

That would totally defeat the purpose of using vector graphics for scaling.


Michael Phillips, Jr.

unread,
Jan 17, 2007, 2:57:35 PM1/17/07
to
The scaling of the enhanced metafile is predicated upon the original
reference device it was recorded on and the bounds used in the
CreateEnhMetafile function.

The only way to rescale it is to play back the enhanced metafile to a device
context that has a scale transform selected into it or re-record the
enhanced metafile with a different reference device and bounds.

In his original post he wanted to save the enhanced metafile as a bitmap and
have the bitmap's bounds match the metafile. To create a bitmap from a
metafile, the bitmap would need it's dimensions scaled to match that of the
enhanced metafile's bounds.

"Ben Voigt" <r...@nospam.nospam> wrote in message
news:eoDXccm...@TK2MSFTNGP04.phx.gbl...

0 new messages