Note that there are some explanatory texts on larger screens.

plurals
  1. POdetecting touch for bitmap that's been drawn with Rect transformations
    text
    copied!<p>For Bitmaps drawn with simple (x,y) coordinates, </p> <pre><code>float _x = x - (bitmap.getWidth() / 2); float _y = y - (bitmap.getHeight() / 2); canvas.drawBitmap(bitmap, _x, _y, null); </code></pre> <p>I can <a href="https://stackoverflow.com/questions/2447564/detect-touch-on-bitmap/2447665#2447665">detect if the bitmap has been touched</a>.</p> <p>I'm drawing a bitmap to the screen with</p> <pre><code> dest = new Rect(0,0,0,0); src = new Rect(0,0,0,0); mSpriteHeight = (int) (sprite_pixel_height * mScale + 0.5f); mSpriteWidth = (int) (sprite_pixel_width * mScale + 0.5f); src.top = 0; src.left = 0; src.bottom = mSpriteHeight; src.right = mSpriteWidth; dest.top = (int) (_x * mScale); dest.bottom = (int) ((_x + mSpriteHeight) * mScale); dest.left = (int) (_y * mScale); dest.right = (int) ((_y + mSpriteWidth) * mScale); canvas.drawBitmap(bitmap, src, dest, null); </code></pre> <p>trying to incorporate the <a href="https://stackoverflow.com/questions/4146328/android-drawbitmap-in-dip/4146430#4146430">screen density</a> because <a href="http://developer.android.com/reference/android/graphics/Canvas.html#drawBitmap%28android.graphics.Bitmap,%20android.graphics.Rect,%20android.graphics.Rect,%20android.graphics.Paint%29" rel="nofollow noreferrer">"This function ignores the density associated with the bitmap. ... so must already have the appropriate scaling factor applied."</a> </p> <p>I haven't been able to detect touches to the translated bitmaps. I must need to do a similar translation using <code>mScale</code>, but I'm lost.</p> <p><strong>Is there a better way to define the src and dest</strong> in my original <code>canvas.drawBitmap(bitmap, src, dest, null);</code>?</p> <p>Anyone know an example where this has been done? I can't seem to find the right search terms to find such an example.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload