如何在Android中重写RenderScript代码

问题描述 投票:0回答:1

我在 Android 中有这段代码,给定一个 int 值,使用 RenderScript 执行一些图像处理(模糊效果)。虽然它非常快速和高效,但它已被弃用,因此我正在寻找其他替代方案。重写它的另一种有效方法是什么?可能是基于 GPU 的解决方案具有类似甚至更快的性能?

private void processImage (int value)
{
    try
    {
        RenderScript rsScript = RenderScript.create(context);
        Allocation alloc = Allocation.createFromBitmap(rsScript, bitmap);

        ScriptIntrinsicBlur blurEffect = ScriptIntrinsicBlur.create(rsScript, Element.U8_4(rsScript));
        blurEffect.setRadius(value);
        blurEffect.setInput(alloc);

        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Allocation outAlloc = Allocation.createFromBitmap(rsScript, output);

        blurEffect.forEach(outAlloc);
        outAlloc.copyTo(output);

        rsScript.destroy();
        output.getPixels(bitmap, 0, width, 0, 0, width, height);
    }
    catch (Exception e) {
    }
}
java android image-processing renderscript
1个回答
0
投票

https://developer.android.com/guide/topics/renderscript/migrate#built-in 是将

ScriptIntrinsic
功能迁移到受支持的功能的好方法。该页面上还有有关如何转换更复杂示例的其他信息。祝你好运! (感谢您实际留意弃用警告)

© www.soinside.com 2019 - 2024. All rights reserved.