@SuppressWarnings({"SuspiciousNameCombination","deprecation"}) public static int calculateMaxBitmapSize(@NonNull Context context){
  WindowManager wm=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
  Display display=wm.getDefaultDisplay();
  Point size=new Point();
  int width, height;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
    display.getSize(size);
    width=size.x;
    height=size.y;
  }
 else {
    width=display.getWidth();
    height=display.getHeight();
  }
  int maxBitmapSize=(int)Math.sqrt(Math.pow(width,2) + Math.pow(height,2));
  Canvas canvas=new Canvas();
  final int maxCanvasSize=Math.min(canvas.getMaximumBitmapWidth(),canvas.getMaximumBitmapHeight());
  if (maxCanvasSize > 0) {
    maxBitmapSize=Math.min(maxBitmapSize,maxCanvasSize);
  }
  final int maxTextureSize=EglUtils.getMaxTextureSize();
  if (maxTextureSize > 0) {
    maxBitmapSize=Math.min(maxBitmapSize,maxTextureSize);
  }
  Log.d(TAG,"maxBitmapSize: " + maxBitmapSize);
  return maxBitmapSize;
}

@ SuppressWarnings ( { "SuspiciousNameCombination" , "deprecation" } ) public static int calculateMaxBitmapSize ( @ NonNull Context context ) { WindowManager wm = ( WindowManager ) context . getSystemService ( Context . WINDOW_SERVICE ) ; Display display = wm . getDefaultDisplay ( ) ; Point size = new Point ( ) ; int width , height ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . HONEYCOMB_MR2 ) { display . getSize ( size ) ; width = size . x ; height = size . y ; } else { width = display . getWidth ( ) ; height = display . getHeight ( ) ; } int maxBitmapSize = ( int ) Math . sqrt ( Math . pow ( width , 2 ) + Math . pow ( height , 2 ) ) ; Canvas canvas = new Canvas ( ) ; final int maxCanvasSize = Math . min ( canvas . getMaximumBitmapWidth ( ) , canvas . getMaximumBitmapHeight ( ) ) ; if ( maxCanvasSize > 0 ) { maxBitmapSize = Math . min ( maxBitmapSize , maxCanvasSize ) ; } final int maxTextureSize = EglUtils . getMaxTextureSize ( ) ; if ( maxTextureSize > 0 ) { maxBitmapSize = Math . min ( maxBitmapSize , maxTextureSize ) ; } Log . d ( TAG , "maxBitmapSize: " + maxBitmapSize ) ; return maxBitmapSize ; }
this method calculates maximum size of both width and height of bitmap . it is twice the device screen diagonal for default implementation ( extra quality to zoom image ) . size cannot exceed max texture size .
