code: public static int convertDPItoPixels(Context context, int dpi) {
          final float scale = context.getResources().getDisplayMetrics().density;
          return (int) (dpi * scale + 0.5f);
      }
docs: Convert a size in dp to a size in pixels
  
  @param context the {@link android.content.Context} to be used
  @param dpi     size in dp
  @return the size in pixels