Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Conversions between twips, pixels, and millimeters using Symbian C++

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60 (All)
CompatibilityArticle
Keywords: TwipsToPixels, PixelsToTwips
Created: User:Technical writer 1 (10 Mar 2009)
Last edited: hamishwillee (30 May 2013)

Contents

Overview

The screen device in Symbian OS provides helper functions to convert a number of pixels to how much physical screen area they occupy (in twips, 1/1440 inches), and vice versa.

Detailed description

Information about how many pixels are required to draw a shape of a certain size in each device is especially useful in touch-enabled UIs, where icons and controls need to have a proper size for use with fingers.

Solution

The following methods convert between pixels and millimeters.

  #define KTwipInMillimeters 0.0176389
 
// Returns the number of pixels corresponding
// to millimeters (x,y) passed as parameter
TPoint MillimetersToPixels( const TPoint& aMm ) const
{
TReal twipsX = (TReal)aMm.iX / KTwipInMillimeters;
TReal twipsY = (TReal)aMm.iY / KTwipInMillimeters;
return iEikonEnv->ScreenDevice()->TwipsToPixels( TPoint((TInt)twipsX,
(TInt)twipsY) );
}
 
// Returns the number of millimeters corresponding
// to pixels (x,y) passed as parameter
TPoint PixelsToMillimeters( const TPoint& aPixels ) const
{
TPoint twips = iEikonEnv->ScreenDevice()->PixelsToTwips(aPixels);
TReal mmX = (TReal)twips.iX * KTwipInMillimeters;
TReal mmY = (TReal)twips.iY * KTwipInMillimeters;
return TPoint((TInt)mmX, (TInt)mmY);
}

Note that all currently available devices have square pixel aspect ratio.

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 30 May 2013, at 04:32.
74 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×