替代Bitmap.getPixel() [英] Alternative to Bitmap.getPixel()

查看:337
本文介绍了替代Bitmap.getPixel()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得前一阵子阅读的替代(又名更快)的方式来执行与getPixel() -ish方法。

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.

我需要运行与getPixel()多次每滴答,这是非常昂贵的它似乎。

I need to run getPixel() multiple times "per-tick," which is very costly it seems.

有谁知道我在说什么?

推荐答案

你可能会想 Bitmap.getPixels(),这将复制位图的任何部分成阵列。从这一点上,可以使用一个简单的数组访问,这比调用 Bitmap.getPixel()多次快得多直接访问任何像素。

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.

您将面临性能与存储在这里的决定:如果您需要查询的像素了很多,如果你的位图很少改变,围绕保持阵列(在具有内存阵列的代价)。如果不是,尽快释放阵列中的兴趣,以确保必要的时候,它可以被收集。显然,避免调用的getPixels()很多 - 的想法是,一​​旦调用它,然后查询阵列多次

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.

这篇关于替代Bitmap.getPixel()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆