Re: Getting crazy with metafiles from clipboard....
- From: "juan" <juan_richeri@xxxxxxxxxxx>
- Date: 5 Jan 2007 05:06:57 -0800
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.
.
- Follow-Ups:
- Re: Getting crazy with metafiles from clipboard....
- From: Michael Phillips, Jr.
- Re: Getting crazy with metafiles from clipboard....
- References:
- Getting crazy with metafiles from clipboard....
- From: juan
- Re: Getting crazy with metafiles from clipboard....
- From: Michael Phillips, Jr.
- Getting crazy with metafiles from clipboard....
- Prev by Date: Re: Get Graphics Object - or Image - from HBITMAP
- Next by Date: Re: Getting crazy with metafiles from clipboard....
- Previous by thread: Re: Getting crazy with metafiles from clipboard....
- Next by thread: Re: Getting crazy with metafiles from clipboard....
- Index(es):
Relevant Pages
|
Loading