title: Draw point on image view with relative coordinates android
body: <p>I'm working on the some geography quiz game.</p>
  
  <p>User have to find some defined on the map.</p>
  
  <p>I've made map point generator that calculates X and Y position relative to size of the image.
  So X and Y of the place on the map are represented as: 
  float * imageWidth = X 
  float * imageHeight = Y;</p>
  
  <p>Now when user touch image view, I have to draw on the map where correct position was.</p>
  
  <p>When image view's scale type is defined as "FitXY" my code calculate position with those relative coordinates and the size of image's bounds, and that works fine, but map is stretched and doesn't look good.</p>
  
  <p>When I use "centerInside" scale type...map image looks fine but my coordinates of the right position aren't point to the right place.</p>
  
  <p>How to convert those coordinates to be corresponding with the real image drawn on the screen?</p>
  
  <p>Also I need touch coordinates of the Bitmap not of the image view...so I can calculate distance between correct place, and touched place.</p>
  
  <p>How to get canvas of bitmap drawn on the screen inside ImageView?</p>
  
  <p>This is a little confusing for me...</p>
  
  <p>Any idea?</p>
  
  <p>Tnx? </p>
  
  <p>EDIT:</p>
  
  <p>This is my code so far:</p>
  
  <p>Drawable drawable = stageImage.getDrawable();
                      Rect imageBounds = drawable.getBounds();</p>
  
  <pre><code>                // height and width of the visible (scaled) image
                  int scaledHeight = imageBounds.height();
                  int scaledWidth = imageBounds.width();
  
                  Matrix inverse = new Matrix();
                  stageImage.getImageMatrix().invert(inverse);
  
                  // map touch point from ImageView to image
                  float[] touchPoint = new float[] { event.getX(),
                          event.getY() };
                  inverse.mapPoints(touchPoint);
  
                  // Relative touch points
                  float relativeX = touchPoint[0] / scaledWidth;
                  float relativeY = touchPoint[1] / scaledHeight;
  
                  // Prevent errors
                  if (relativeX &lt; 0) {
                      relativeX = 0;
                  }
  
                  if (relativeX &gt; 1) {
                      relativeX = 1;
                  }
  
                  if (relativeY &lt; 0) {
                      relativeY = 0;
                  }
  
                  if (relativeY &gt; 1) {
                      relativeY = 1;
                  }
  
  
                  touchX = event.getX();
                  touchY = event.getY();
  
       //THIS WORKS FINE!!!!!
                  // Draw touched point
                  stageImage.drawTouchedSpot(touchX, touchY);
  
                  // Get correct relative position and draw it
                  double correctRelativeX = gameHandler
                          .getCurrentMapElement().getxCoordinate()
                          * imageBounds.width();
                  double correctRelativeY = gameHandler
                          .getCurrentMapElement().getyCoordinate()
                          * imageBounds.height();
  
      //THIS IS NOT RIGHT WHEN STAGE IMAGE SCALE TYPE IS "CENTER INSIDE"
                  stageImage.drawFlag(correctRelativeX, correctRelativeY);
  </code></pre>