Freigeben über


Convertion from screen resolution to print resolution

Handled a strange issue, wanted to share: One of my customers wanted to drag-drop an EMF file from her application to Word now the basic problem here is there are incompatibilities between EMFs in windows and .NET and that's why they can not use IDataobject here, details on KB 323530

We tried using different approaches like:

1) Using APIs to get the window below the pointer getting the handle and pasting the emf(which never worked properly, because it was tooinconsistant to be used in a real world enviornment)

2) Converting .NET emf to windows emf putting it to clipboard dropping an empty string to word then doing Selection.Paste (word automation), which was not in sync with customers use of DataObejct

3) So we used the HTML clipboard format(with <img src="emf_file_name">), something like 

Version:0.9\r\nStartHTML:00000000\r\nEndHTML:00000000\r\nStartFragment:00000000\r\n";

s += "EndFragment:00000000\r\n<html><body>\r\n<!--StartFragment -->\r\n";

s += "<img src=\"<path>\\<filename>\">";

s += "<!--EndFragment-->\r\n</body>\r\n</html>";

added this to dataobject and dropped it in word, worked perfectly BUT.....

When you drop the image directly (from explorer) in word it displays in its print resolution, when you drop it using HTML the image is displayed in its screen resolution and in this specific case these two are very different resolutions, so the resolution to this came from ....no programming :) pure mathematics..

we finally came up with

Equation 1:

image_width                            image_height

============== =====  X  ==== ===============  = actual print size

image_horiz_resoltuon(dpi)     image_verti_resoltuon(dpi) 

Equation 2:

image_width                            image_height

============== =====  X  ==== ===============  = actual screen size

Average monitor resolution(96)         Average monitor resolution(96) 

 

came up with the conversion equation...and bang.....!! one of the most importand help came from

https://blogs.msdn.com/fontblog/archive/2005/11/08/490490.aspx

https://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/highdpi.asp

Comments