public void zoomToFit(int availableWidth,int availableHeight,boolean allowZoomIn,int horizontalMargin,int verticalMargin){
  int sceneWidth=myImage.getWidth();
  int sceneHeight=myImage.getHeight();
  int shadowSize=hasDropShadow() ? myUseLargeShadows ? SHADOW_SIZE : SMALL_SHADOW_SIZE : 0;
  availableWidth-=shadowSize;
  availableHeight-=shadowSize;
  if (sceneWidth > 0 && sceneHeight > 0) {
    int hDelta=availableWidth - sceneWidth;
    int xMargin=0;
    if (hDelta > 2 * horizontalMargin) {
      xMargin=horizontalMargin;
    }
 else     if (hDelta > 0) {
      xMargin=hDelta / 2;
    }
    int vDelta=availableHeight - sceneHeight;
    int yMargin=0;
    if (vDelta > 2 * verticalMargin) {
      yMargin=verticalMargin;
    }
 else     if (vDelta > 0) {
      yMargin=vDelta / 2;
    }
    double hScale=(availableWidth - 2 * xMargin) / (double)sceneWidth;
    double vScale=(availableHeight - 2 * yMargin) / (double)sceneHeight;
    double scale=Math.min(hScale,vScale);
    if (!allowZoomIn) {
      scale=Math.min(1.0,scale);
    }
    setScale(scale);
  }
}

public void zoomToFit ( int availableWidth , int availableHeight , boolean allowZoomIn , int horizontalMargin , int verticalMargin ) { int sceneWidth = myImage . getWidth ( ) ; int sceneHeight = myImage . getHeight ( ) ; int shadowSize = hasDropShadow ( ) ? myUseLargeShadows ? SHADOW_SIZE : SMALL_SHADOW_SIZE : 0 ; availableWidth -= shadowSize ; availableHeight -= shadowSize ; if ( sceneWidth > 0 && sceneHeight > 0 ) { int hDelta = availableWidth - sceneWidth ; int xMargin = 0 ; if ( hDelta > 2 * horizontalMargin ) { xMargin = horizontalMargin ; } else if ( hDelta > 0 ) { xMargin = hDelta / 2 ; } int vDelta = availableHeight - sceneHeight ; int yMargin = 0 ; if ( vDelta > 2 * verticalMargin ) { yMargin = verticalMargin ; } else if ( vDelta > 0 ) { yMargin = vDelta / 2 ; } double hScale = ( availableWidth - 2 * xMargin ) / ( double ) sceneWidth ; double vScale = ( availableHeight - 2 * yMargin ) / ( double ) sceneHeight ; double scale = Math . min ( hScale , vScale ) ; if ( ! allowZoomIn ) { scale = Math . min ( 1.0 , scale ) ; } setScale ( scale ) ; } }
zooms the view to fit .
