android - Android 位图中 getPixel 和 getPixel 的更快替代方案?

标签 android performance android-ndk android-bitmap renderscript

我正在为我的 Bitmap 使用方法 getPixelsetPixel,但它太慢了(getPixels 也一样) )。我想处理位图的每个像素,然后创建另一个位图。如何通过 RenderScript 或使用 C++ 访问像素?我认为它们更快,但我不知道该怎么做。

这就是我使用 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()获取所有像素,修改byte[]中的值,然后调用setPixels()存储一次所有像素。对每个单独的像素调用 setPixel() 的开销会降低您的性能。

如果仍然不够快,您可以将数组传递给 NDK 函数。

如果您正在进行相机图像的实时处理,您可以获得 even fancier .

关于android - Android 位图中 getPixel 和 getPixel 的更快替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30559211/

相关文章:

android - 纠结谷歌测试

android - Android 5.1设为优先模式

Android单选按钮文字加粗

c# - 可怕又大的 LINQ 语句优化

android - 无法在 Windows/Cygwin 上为 Android NDK 构建外部 OpenSSL 库

android - android NDK 编译器是否支持内联汇编? (即 asm 或 __asm 关键字?)

Android - CoordinatorLayout 中的滚动和 Bottom Sheet

android - 设置宽度以匹配 ConstraintLayout 中的约束

android - 在 recyclerView 中呈现 imageView 延迟的问题

node.js - Nodejs 每秒请求数和并发调用数