Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did it with a mask like Scotty indicated, but I ran into more problems. Basically the colors returned by getPixel were slightly different than in the mask file. What I did was to load the mask in memory with scaling disabled and with full color options like this:</p> <pre><code>BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inTargetDensity = 1; bitmapOptions.inDensity = 1; bitmapOptions.inDither = false; bitmapOptions.inScaled = false; bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; mask = BitmapFactory.decodeResource(appContext.getResources(), resMask, bitmapOptions); </code></pre> <p>Then I looked up the coords from the scaled image like this:</p> <pre><code>ImageView map = (ImageView) findViewById(R.id.image); Drawable drawable = map.getDrawable(); Rect imageBounds = drawable.getBounds(); int scaledHeight = imageBounds.height(); int scaledWidth = imageBounds.width(); int scaledImageOffsetX = Math.round(event.getX()) - imageBounds.left; int scaledImageOffsetY = Math.round(event.getY()) - imageBounds.top; int origX = (scaledImageOffsetX * mask.getWidth() / scaledWidth); int origY = (scaledImageOffsetY * mask.getHeight() / scaledHeight); if(origX &lt; 0) origX = 0; if(origY &lt; 0) origY = 0; if(origX &gt; mask.getWidth()) origX = mask.getWidth(); if(origY &gt; mask.getHeight()) origY = mask.getHeight(); </code></pre> <p>and then I applied mask.getPixel(origX, origY). It only works when the image is scaled with android:scaleType="fitXY" inside the ImageView otherwise the coords are off.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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