Positioning a scaled bitmap makes the position jump a little
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6835224/android-bitmap-canvas-offset-after-scale">Android Bitmap/Canvas offset after scale</a>  </p>
</blockquote>



<p>I use this code to scale and position a bitmap behind another bitmap, so the spark is placed behind the ball but they should always have the same center position (each bitmap must have its center over the others center at all times):</p>

<pre><code>int x = (((int)((sparkle.getWidth() * sparkleTodayScale))) / 2) - (ball.getWidth() / 2);
int y = (((int)((sparkle.getHeight() * sparkleTodayScale))) / 2) - (ball.getHeight() / 2);
sparkX = pos[0] - x;
sparkPos[1] = pos[1] - y;

canvas.save();
canvas.scale(sparkleTodayScale, sparkleTodayScale, sparklePos[0], sparklePos[1]);
canvas.drawBitmap(sparkle, sparklePos[0], sparklePos[1], ball.getSparklePaint());
canvas.restore();
</code></pre>

<p>pos is the position of the ball bitmap, but the sparkle jumps around, it seems it is jumping one pixel as it scales.</p>

<p>What am I doing wrong here? How can I make the centers always aligned?</p>

<p>Thank you
<br>Søren</p>
