Bitmap.getPixel() 的替代方法
我记得不久前读过有关执行 getPixel()
-ish 方法的替代(也称为更快)方法的文章。
问题是,我不记得我在哪里读到的,而且我已经彻底搜索过......我想。
答案与将位图锁定在内存中或类似的事情有关。
我需要“每次更新”多次运行 getPixel()
,这看起来成本非常高。
有人知道我在说什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在考虑
Bitmap.getPixels()
,它将把位图的任何部分复制到数组中。从那时起,您可以使用简单的数组访问直接访问任何像素,这比多次调用Bitmap.getPixel()
快得多。您将在这里面临性能与内存的决定:如果您需要大量查询像素并且位图很少更改,请保留该数组(以将该数组保留在内存中为代价)。如果没有,请尽快释放对该数组的兴趣,以确保必要时可以收集。显然,避免多次调用
getPixels()
- 其想法是调用一次,然后多次查询数组。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 callingBitmap.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.