Bitmap.getPixel() 的替代方法

发布于 2024-09-28 13:40:12 字数 218 浏览 0 评论 0原文

我记得不久前读过有关执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

镜花水月 2024-10-05 13:40:12

您可能正在考虑 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文