Re: Getting crazy with metafiles from clipboard....




Michael Phillips, Jr. ha escrito:

Here is the method that I use to convert and scale my metafile to the
correct bitmap dimensions:

HDC hdcScreen = GetDC(NULL);
int vRes = GetDeviceCaps(hdcScreen, VERTRES);
int hSize = GetDeviceCaps(hdcScreen, HORZSIZE);
int vSize = GetDeviceCaps(hdcScreen, VERTSIZE);
int dpiX = GetDeviceCaps(hdcScreen, LOGPIXELSX);
int dpiY = GetDeviceCaps(hdcScreen, LOGPIXELSY);
float dpiScreenX = ((float)hRes / (float)hSize) * 25.4f; // 25.4mm per inch
float dpiScreenY = ((float)vRes / (float)vSize) * 25.4f; // 25.4mm per inch
float dpiScaleX = (float)dpiScreenX / dpiX;
float dpiScaleY = (float)dpiScreenY / dpiY;
ReleaseDC(NULL, hdcScreen);

// from the metafile header
int imageWidth = (int)ceil(((double)mfh.Bounds.Width / mfh.DpiX) *
(dpiX*dpiScaleX)); // bitmap's width
int imageHeight = (int)ceil(((double)mfh.Bounds.Height / mfh.DpiY) *
(dpiY*dpiScaleY));// bitmap's height

I use gdi+ to create a bitmap with the above dimensions and use DrawImage to
draw and scale the enhanced metafile to the bitmap.



"juan" <juan_richeri@xxxxxxxxxxx> wrote in message
news:1167928757.432211.125980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi!
I've been trying for 2 days and I couldn't get any solution.

Here is my problem. I need to save the content of the CF_ENHMETAFILE
(or CF_METAFILEPICT)
to disk as a BMP.


Even if in the clipboard there is a CF_DIB or CF_BITMAP, I need to work

with metafiles.


So the first step (the one that is failing) is to save ENHMETAFILE as
.emf...


Here is my little code:
if( IsClipboardFormatAvailable(CF_ENHMETAFILE) ) {
HENHMETAFILE hEnhMF =
(HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE);
CopyEnhMetaFile(hEnhMF, "c:\\emf.emf");



}


Very simple... but when I see this .emf file, the dimension in pixels
is different
to the original image!

I use word as the source of the image (e.g. selecting the complete word

document).
For example, I copy an image from Word and I paste it in Paint...
(paint uses the
CF_DIB) and the number of pixels is 361x540


But when I open the c:\emf.emf in paint the resulting img dimension is
239x358!!!


If I use the GetEnhMetaFileHeader function, the ENHMETAHEADER.rclBounds

also
returns 239x358!!!
rclFrames returns widht of 9.5 cms while in my screen it is 14 cms!
So I deduce that information that is in the metafile is wrong!!!
However if I make a paste-special of Picture (Metafile) in wordpad, it
works fine....

It is not a word issue, if I copy from paint it is the same!


I've made a simple program that just makes:
if( IsClipboardFormatAvailable(CF_ENHMETAFILE) ) {
HENHMETAFILE hEnhMF =
(HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE);
EmptyClipboard();
HANDLE hRet = SetClipboardData(CF_ENHMETAFILE, (HANDLE)hEnhMF);



}


CloseClipboard();

So I remove all the other formats only leaving CF_ENHMETAFILE and it is

the
same! when I paste it in Paint or in any other program the pasted image

contains
good dimensions!!!!


How can I get and redimension the generated .emf file to the proper
dimension?
I will then use CXImage or work with HBITMAPs and HDCs to save it as
.bmp but
I have this problem...


Thanks


Thanks!
However I cannot figure out these members:
mfh.Bounds.Width
mfh.DpiX
mfh.Bounds.Height
mfh.DpiY

since in the ENHMETAHEADER they don't exist...

Thanks again.

.



Relevant Pages

  • Re: Getting crazy with metafiles from clipboard....
    ... Here is the method that I use to convert and scale my metafile to the ... int hSize = GetDeviceCaps; ... I use gdi+ to create a bitmap with the above dimensions and use DrawImage to ... But when I open the c:\emf.emf in paint the resulting img dimension is ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Getting crazy with metafiles from clipboard....
    ... The above comes with the Metafile header provided by gdi+. ... The same information is available with the ENHMETAHEADER ... int hSize = GetDeviceCaps; ... But when I open the c:\emf.emf in paint the resulting img dimension is ...
    (microsoft.public.win32.programmer.gdi)
  • Patch 5/23 - Bitmaps, Cpumasks and Nodemasks
    ... P5.bitmap_extensions - Optimize and extend bitmap. ... -int bitmap_empty ... -void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits); ... +static inline void bitmap_clear ...
    (Linux-Kernel)
  • [Patch 5 of 17] cpumask v4 - Optimize and extend bitmap.
    ... mask5-bitmap-extensions - Optimize and extend bitmap. ... -int bitmap_empty ... -void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits); ... +static inline void bitmap_clear ...
    (Linux-Kernel)
  • Re: Getting header info of a BMP file
    ... int infoSize; ... Specifies the number of bytes required by the structure. ... Specifies the width of the bitmap, ... specify the red, green, and blue components of each pixel. ...
    (comp.lang.java.programmer)

Loading