Convert Pixel to Pixel By HVGA - Android Graphics

Android examples for Graphics:Pixel

Description

Convert Pixel to Pixel By HVGA

Demo Code


//package com.java2s;

import android.content.Context;

import android.util.DisplayMetrics;

public class Main {

    public static float px2pxByHVGA(Context context, float pxValue) {
        final float density = getDisplayMetrics(context).density;
        return ((pxValue + 0.5f) * density + 0.5f);
    }// w w  w.  j av  a2s.c om

    public static DisplayMetrics getDisplayMetrics(Context context) {
        if (context == null) {
            return null;
        }
        return context.getResources().getDisplayMetrics();
    }
}

Related Tutorials