Search code examples
phpandroiddensity-independent-pixel

android convert dip to pixels?


my issue is i want to re-size all images inside the post by showing 2 images per row

my app send the width of screen to the php api the php api must convert the dip to pixels and set image width 50% of screen dip

this is what aim doing so far

Display d = getWindowManager().getDefaultDisplay(); 

int w = display.getWidth();  
int h = display.getHeight(); 

String response = get_html_postinfo("bla.php?postid=1&h="+h+"&w="+w);

//response will append it to WebView

in php side

$screen_dip_w = $_GET['w'];
$screen_dip_h = $_GET['h'];

//i want this dip to be converted to pixel how ?
$screen_px_w = ( ? X $screen_dip_w );

$set_image_w = $screen_px_w/2;

any idea ? thank u


Solution

  • Display.getWidth() and Display.getHeight() already return the size of the screen in pixels, no conversion is required.

    Also, I recommend switching to using Display.getSize(Point outSize) as the width and height methods are deprecated.

    developer.android.com/reference/android/view/Display.html