[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

Problem with TMetafile: The size is not kept!

Dear EE!
I want to convert a Object (like Mathtype Equation, ChemSketch Object)  from Word to Bitmap.
So I do these work:
Copy Object to Clipboard (I do it manually). Then Use TMetafile to Redraw it (I do it by Delphi): TMetafile.Assign(Clipboard) and then:
TBitmap.Width:= TMetafile.Width; TBitmap.Height:= TMetaFile.Height;
TBitmap.Canvas.Draw(0,0,TMetaFile)
But a problem: the size of the image(width x height) is changed (become smaller)
Can you suggest me some enhanced Component or show me how to fix this problem?
Thanks much!
0
coldboy
Asked:
coldboy
  • 2
1 Solution
 
pcsentinelCommented:
Just a guess,

this may be because Word is using a different base measurement for the metafiles.

After your assign of the tmetafile from the clipboard, extract the MMWidth and MMHeight values

the convert these values to pixels on screen

i.e. if the mmwidth is 100 then
you need to find out what is 100mm in your screen resolution


GetDeviceCaps(Screen.Handle,LogPixelsX);

this gives you logical pixels per inch across the screen

divide  this by 25.4 to get pixels per mm and then multiply by MMwidth value this should give you the width you need to set the bitmap to

for height use

GetDeviceCaps(Screen.Handle,LogPixelsY);

regards
0
 
coldboyAuthor Commented:
Thanks! But I see using Screen.Pixelperinch is more easy.
0
 
pcsentinelCommented:
Thats fine, the only thing you have to watch out for is that delphi gets screen.pixelsperinch from a call to

GetDeviceCaps(Screen.Handle,LogPixelsY);

now thats fine because in 99.999% of screens a pixel is square. However if you where to use the same code say to write to a printer, then its not always the case and its best to get individual measurements for X & Y.

But its fine for what your doing

Good Luck



0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now