Convert Twips to pixel

  • Thread starter Thread starter perspolis
  • Start date Start date
P

perspolis

Hi all
I have some points in twips measurement.how can I convert them to pixel
measurement ?

thanks
 
perspolis said:
Hi all
I have some points in twips measurement.how can I convert them to
pixel measurement ?

wasn't twips something from the VB5/6 world?

If you retrieve the coordinates in .net code, you can always get them
in pixel format.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
perspolis said:
I have some points in twips measurement.how can
I convert them to pixel measurement ?

A twip is 1/1440 of an inch, so it depends on the resolution of the
screen being used and will vary between computers. You need to know
the screen size in pixels (easy to discover) and in inches (harder or
impossible at run-time) to do this conversion. It will probably be
easier for you to redesign the system from scratch to use pixels.

Eq.
 
Paul said:
A twip is 1/1440 of an inch, so it depends on the resolution of the
screen being used and will vary between computers. You need to know
the screen size in pixels (easy to discover) and in inches (harder or
impossible at run-time) to do this conversion. It will probably be
easier for you to redesign the system from scratch to use pixels.

This is the correct advice - convert to using pixels, which is the .NET
way of doing things.

However, for those that are interested, it is possible to use Reflector
to examine the Microsoft.VisualBasic.Compatibility dll, in which is
contained translations of the VB6 methods Screen.TwipsPerPixelX and
Screen.TwipsPerPixelY (you can guess what they do). This is the direct
output from Reflector; interested parties will not find it hard to
pursue undefined references. As Paul E Collins suggests, it is indeed
'hard' to do at runtime:

private static void SetUpTwipsPerPixel(bool Force /* = false */)
{
if (!Support.m_IsTwipsPerPixelSetUp || Force)
{
Support.m_TwipsPerPixelX = 0;
Support.m_TwipsPerPixelY = 0;
try
{
IntPtr ptr1 =
NativeMethods.GetDC(NativeMethods.NullIntPtr);
if (!ptr1.Equals(NativeMethods.NullIntPtr))
{
Support.m_TwipsPerPixelX = 1440 / ((double)
NativeMethods.GetDeviceCaps(ptr1, 0x58));
Support.m_TwipsPerPixelY = 1440 / ((double)
NativeMethods.GetDeviceCaps(ptr1, 90));

NativeMethods.ReleaseDC(NativeMethods.NullIntPtr, ptr1);
}
}
catch (Exception exception1)
{
ProjectData.SetProjectError(exception1);
ProjectData.ClearProjectError();
}
Support.m_IsTwipsPerPixelSetUp = true;
if ((Support.m_TwipsPerPixelX == 0) ||
(Support.m_TwipsPerPixelY == 0))
{
Support.m_TwipsPerPixelX = 15;
Support.m_TwipsPerPixelY = 15;
VB6Errors.RaiseError(7,
Resources.GetResourceString("Misc_SetUpTwipsPerPixel"));
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top