对于getPixel和getPixel在Android的位图更快的替代方案? [英] Faster alternative for getPixel and getPixel in Android Bitmap?
问题描述
我使用的方法 getPixel
和的setPixel
我的位图
,它是如此缓慢(的getPixels
太)。我要处理的位图
的每一个像素,然后创建另一个位图
。我怎样才能获得通过RenderScript访问像素或使用C ++?我认为他们是速度更快,但我不知道该怎么办。
I'm using the methods getPixel
and setPixel
for my Bitmap
and it's so slow (getPixels
too). I want to process every pixel of the Bitmap
and then create another Bitmap
. How can I get access to pixels by RenderScript or using C++? I think they are faster but I don't know how to do .
这是我使用的是什么 getPixel
/ 的setPixel
:
This is what I do using getPixel
/ setPixel
:
bitmap.getPixels(colorArray, 0, width, 0, 0, width, height);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int g = Color.green(colorArray[y * width + x]);
int b = Color.blue(colorArray[y * width + x]);
int r = Color.red(colorArray[y * width + x]);
//some color changes ....
colorArray[y * width + x] = Color.rgb(r, g, b);
returnBitmap.setPixel(x, y, colorArray[y * width + x]);
}
}
谢谢!
推荐答案
使用的getPixels()
来得到所有的像素,在字节[]
,然后调用的setPixels()
来的所有像素存储一次。调用的开销与setPixel()
对每个像素是杀你的表现。
Use getPixels()
to get all the pixels, modify the values in the byte[]
, then call setPixels()
to store all the pixels at once. The overhead of calling setPixel()
on each individual pixel is killing your performance.
如果它仍然不够快,你可以在阵列传递到NDK的功能。
If it's still not fast enough, you can pass the array to an NDK function.
如果你正在做的摄像机图像活处理,可以得到更炫
If you're doing live processing of Camera images, you can get even fancier.
这篇关于对于getPixel和getPixel在Android的位图更快的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!