Welcome!

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

Reply
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom
Accepted Solution

DPI formula

[ Edited ]

Hi everyone

 

I want to add focusable Images in my app and want the images to fit a specific part of all blackberry screens, I heard about a DPI formula, anyone know anything about this?

 

Thank you

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

Please correct me if I am Wrong with my formula:

 

   long h=Display.getHorizontalResolution();

   long v=Display.getVerticalResolution();

   long hv= h*v;//PPM

   double hvi=hv*  39.3700787 ;

 

The "long h" and "long v", give the same values and the answer to this formula is 3.710443460782276E9

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

seeing as no one is replying. is there a function that I can use in order to make the images in my app more or less the same size?

Developer
Posts: 16,786
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

it would be useful if you could keep one thread for one question, and if you could refrain to post your question to all threads a search for the topic turned up.
you can link to relevant threads, but resurrecting them from a 3 year slumber is only cluttering the board view and making it more unlikely for anybody to answer you.
----------------------------------------------------------
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
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

Thank you Simon I will keep that in mind for the future reference

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

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

I am responding to this:

 

"Please correct me if I am Wrong with my formula:

 

   long h=Display.getHorizontalResolution();

   long v=Display.getVerticalResolution();

   long hv= h*v;//PPM

   double hvi=hv*  39.3700787 ;

 

The "long h" and "long v", give the same values and the answer to this formula is 3.710443460782276E9"

 

Just for clarification resolution is the desnity of the pixles on the screen.  A lot of people mix this up with screen size, so they say their screen resoltuion is 320 * 240, which of course is actually the screen size. 

 

In your code, h and v are already resolutions - they are pixels in a meter.  Both are the same because BB screens all have the same resolution vertically and horizontally.  If you wanted to convert this to dpi (dots/pixels per inch) you would divide by 39.3700787.

 

So

 

double inchesInAMeter = 39.3700787; 

double hvi= ((double) Display.getHorizontalResolution()) / inchesInAMeter;

 

should give you what you want.

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

[ Edited ]

Theank you for replying Peter, I have one more question. I used the formula that you gve me and I got the following:

8520  - 162dpi.

9780 - 246dpi.

 

I did research before hand to get all the DPI's for the cellphones that are in my country and the research stated:

8520  - 164dpi.

9780 - 184dpi.

 

Do you think the DPI information I got online is inacurate? because I compare my answer from the coded formula to the actual DPI's in the chart I created (Based on research online) to make sure My info is acurate in my code.

 

I am assuming that if the screen resollutions are the same the DPI will be the same, I just checked out another lin which says that 480 x 360 = 246 DPI (the article is on the 9360) so I am assuming that the DPI applies to the 9780 as well?

 

Thank you

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

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

I would trust the calculation, not the documentation.

 

Here is some different documentation for the 9780....

http://www.gsmarena.com/blackberry_bold_9780-3431.php

 

"I am assuming that if the screen resollutions are the same the DPI will be the same"

As noted previously, a lot of people use screen resolution to mean the number of pixels on the screen, rather than the density of the pixels.  Since I'm not sure what meaning you are using here I can't answer the question. 

 

But when the terms are used correctly, resolution and dpi are technically the same thing, just they might be measured with different units.

 

BTW, I recommend that you do this calculation in your startup, and have your application size everything appropriately.  I suggest this is a lot easier, because you only need one build.  I suspect you are doing the calculation on the Simulator and then having a build for each resolution. 

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

Thanks Peter Smiley Happy

Developer
Posts: 285
Registered: ‎08-06-2010
My Device: Z10

Re: getting the name of an image from the directory and adding more than one MenuItem to Camera and DPI formula

Here's a class to convert DPI to the Android format:

 

public abstract class DisplayUtils {
	
	public static final float density = DisplayUtils.getDensity();

	private static float getDensity() {

        float dpi = (Display.getHorizontalResolution() * 0.0254f);
if (dpi <= 135.0f) { return 0.75f; // LDPI } else if (dpi <= 175.0f) { return 1.0f; // MDPI } else if (dpi <= 250.0f) { return 1.5f; // HDPI } else { return 2.0f; // XHDPI } } public int convertPxToDp( int px ) { return (int) ( px * DisplayUtils.density + 0.5f ); } }

 



Follow me on twitter @RileyGB - https://twitter.com/RileyGB
View my BB10 OpenSource projects - https://github.com/RileyGB/BlackBerry10-Samples