Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 18
Registered: ‎05-17-2012
My Device: NA
My Carrier: NA
Accepted Solution

Relation between Pixels and Points in blackberry

I need to know the relation between points and pixels and how it affects different BB 7.0 and lower version devices.

I have a project which parses values of width and height of components to be displayed in points and I have converted them into pixels and shown on different devices using the following formula.

fldwidth  = fldwidth*Display.getWidth()/100
fldheight = fldheight*Display.getHeight()/100

where initially the values of fldwidth and fldheight has pt values in decimal.

Am I correct

Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Relation between Pixels and Points in blackberry

you can use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/Display.html#getHorizon... and its vertical counterpart to retrieve the PPM of the device.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Relation between Pixels and Points in blackberry

[ Edited ]

Similar question on stack overflow:


Here is the answer I posted there:


A point is, by definition, 1/72 of an inch -  -  - see Wikipedia Point_(typography)


The size of pixel is dependent on the screen resolution on the device.  Just to be clear, this is resolution normally stated in dots per inch (dpi).  This is not the common usage for the term resolution which is the pixel height and width of the screen.  People use resolution in this way incorrectly.  Resolution is the density of dots on the screen, not the number of pixels on the screen. 


The point here is that there is no relationship between the number of pixels displayed on the screen with the number of pixels that are required for a point.  You can not use the conversion that you are attempting. 


To determine the number of pixels that match 1 point, you must get the resolution of the screen.  BB provides two methods for this:


Fortunately, these will give you the same value on all BBOS (Java) devices, as all BBOS devices have the same vertical and horizontal resolution. 


The value supplied is the number of pixels in one metre.  So all you need to do is determine how many 1/72s of an inch there are in 1 metre, divide one of these values by that number, and then you have the number of pixels in a point.


Because of integer arithmetic, when doing this calculation, I would multiply by the point size you are trying to achieve before doing the division.  For example:


    int pixelSizeReqd = pointSizeReq * 
    Display.getHorizontalResolution() / pointsInOneMetre;

 And by the way, just call Display.getHorizontalResolution() once and reuse the returned value.  I am not sure about getHorizontalResolution(), but I do know that some Display methods, for example, getHeight() and getWdith() are 'expensive' so should be avoided if possible.  The value is not going to change anyway!



Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Relation between Pixels and Points in blackberry

Assume you want a size of 57 points. So the calculation is:

int pixelSizeReqd = 57 * Display.getHorizontalResolution() / pointsInOneMetre;

You shouldn't replace Display.getHorizontalResolution() with a figure - it will be different on different devices and there is no need for you to try to fix this value for yourself.

How many points are there in 1 metre? You can do the math, convert a 1/72 inch into metres and then divide 1 metre by this. Or you can type into Google "how many points in a meter" and get the answer 2,834.64567. We don't need the accuracy, so we just use integer arithmetic to give us this:

int pixelSizeReqd = 57 * Display.getHorizontalResolution() / 2834;