title: Java swt - Get actual x,y coordinates from Image after scaling and zooming
body: <p>I have an image that has been scaled to fit.  From the scaled image a user is selecting a rectangle.</p>
  
  <p>I then re-draw based on this selection:</p>
  
  <pre><code>gc.drawImage(imageDisplayed, minX, minY, width, height, imageDisplayed.getBounds().x,  imageDisplayed.getBounds().y, imageDisplayed.getBounds().width, imageDisplayed.getBounds().height );
  </code></pre>
  
  <p>So now I want to be able to get the original co-ordinate from the scaled AND zoomed image.  Is this correct?:</p>
  
  <pre><code>public Coordinate GetScaledXYCoordinate(int oldX, int oldY, int width, int height, int scaledWidth, int scaledHeight)
  {       
      int newX = (int)(oldX * width)/scaledWidth;
      int newY = (int)(oldY * height)/scaledHeight;
  
      Coordinate retXY = new Coordinate(newX, newY);
      return retXY;
  }
  
  
  public Coordinate GetZoomedXYCoordinate(int oldX, int oldY, int startX, int endX, int startY, int endY,
          int width, int height,int scaledWidth, int scaledHeight)
  {       
      // First get x,y after scaling
      Coordinate xy = GetScaledXYCoordinate(oldX, oldY, width, height, scaledWidth, scaledHeight);
  
      // Now get x.y after zooming
      int minX = Math.min(startX, endX);
      int minY = Math.min(startY, endY);
  
      int maxX = Math.max(startX, endX);
      int maxY = Math.max(startY, endY);
  
      int rectWidth = maxX - minX;
      int rectHeight = maxY - minY;
      return GetScaledXYCoordinate(xy.getX(), xy.getY(), width, height, scaledWidth, scaledHeight);
  }
  </code></pre>
  
  <p><strong>Note:</strong> I would like an algorithm that would work for many zooms, not just one zoom. </p>
  
  <p><strong>Update:</strong></p>
  
  <p>Ideally, I would like a function that takes a screen Point X,Y, and returns the original image X,Y. The function would still return the correct X,Y after scaling and zooming </p>