views:

64

answers:

1

I remember a while ago reading about an alternative (aka faster) way to perform a "getPixel()-ish" method. Problem is, I don't remember where I read that, and I've searched thoroughly.. I think.

The answer had something to do with locking the Bitmap in memory, or something like that. I need to run getPixel() multiple times "per-tick," which is very costly it seems.

Does anyone know what I'm talking about?

+1  A: 

You're probably thinking about Bitmap.getPixels(), which will copy any part of the Bitmap into an array. From that point on, you can directly access any pixel using a simple array access, which is a lot faster than calling Bitmap.getPixel() multiple times.

You'll be facing a performance vs. memory decision here: If you need to query pixels a lot and if your bitmap rarely changes, keep the array around (at the expense of having that array in memory). If not, release interest in the array as soon as possible to ensure that it can be collected when necessary. Obviously, avoid calling getPixels() a lot - the idea is to call it once and then query the array many times.

EboMike
Well, it wasn't that, but that certainly is an option. The article I read was much more complicated.. way over my head. But now that I'm running into performance issues I thought I'd try and figure it out.
Snailer
Well, depends on what you have in mind. This is basically like "locking a read-only surface" in a graphics library. If you want to be hardcore, you could do `Bitmap.copyPixelsToBuffer`, but again, assuming that you have a static bitmap that is not too large, the easiest drop-in replacement would be to call `getPixels` on it once and look that array up.
EboMike