Alternative to Bitmap.getPixel()

[亡魂溺海] 提交于 2019-12-12 16:58:44

问题


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:


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.



来源:https://stackoverflow.com/questions/4011327/alternative-to-bitmap-getpixel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!