Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top