Checking individual pixels in a bitmap, how to store the bitmap?
<p>I'm doing an application where I need to detect if the user is selecting a longitude/latitude pair that's on land or at sea on a MapView. I could get this answered by sending a request to the Google Maps service, but I'd rather it work offline too. So I've come up with two ways that this could function, and since I'm rather green on the Bitmap vs. memory area I thought I'd get your input.</p>

<p>The main idea is that I'm storing a small black and white bitmap of the map area I want to cover (say 200x200 px). When a user selects a longitude/latitude pair, then that pair is converted into a set of x,y pixels and I check if the pixel coordinates points to a black pixel(land) or a white pixel(sea/water). Here's the two methods I've come up with so far.</p>

<p><strong>Option A</strong></p>

<p>Lazy load the Bitmap when the user is about to select the long/lat pair and use <a href="http://developer.android.com/reference/android/graphics/Bitmap.html#getPixel%28int,%20int%29" rel="nofollow"><code>getPixel()</code></a> to check if it's at land or sea. Keep a WeakReference to the image at let it be garbage collected whenever the GC comes around.</p>

<p><strong>Option B</strong></p>

<p>Keep each pixel coordinate pair of the bitmap in a SQLite database and do a lookup everytime the user is about to select a long/lat pair.</p>

<p>I'm guessing that <strong>A</strong> is the best one speed-wise (ignoring the overhead of reading the bitmap from the disk in the first place), but is it costly to keep the bitmap in memory, battery-wise?</p>

<p>If you have any other suggestions on how to do this then I would love to here them :)</p>
