title: Affinetransform center scale coordinates
body: <p>I have a graphics.drawImage with a buffer that I want to draw center scaled and a Rectangle with the coordinates and scale I want the buffer to be drawn as.</p>
  
  <pre><code>tr2.translate(buffer.getWidth()/2, buffer.getHeight()/2);
  tr2.scale((double)rect.width/buffer.getWidth(),(double) rect.height/buffer.getHeight());
  tr2.translate(-buffer.getWidth()/2, -buffer.getHeight()/2);
  </code></pre>
  
  <p>The question is what do I need to do to get it aligned to the rectangle coordinates?</p>
  
  <p>The buffer coordinates should be mapped to rect loaction.</p>
  
  <p>So if the top left corner of rect is (30,80) we want buffer top left corner after the scale to be also (30,80) </p>
  
  <p>The problem is if before the scale the top left corner was (0,0) now it is something like(-15,10) depending on the scale which we need to find.</p>