Search code examples
renderscriptandroid-renderscript

Renderscript for Bitmap crop


It looks like Android SDK's BitmapRegionDecoder uses Skia for decoding a part of the specified bitmap. Under the hood, it uses an appropriate code (jpeg, png etc) for the same. I'm looking at ways to optimize this using Renderscript.

Is it possible to define a Renderscript kernel function to ignore certain data from input allocation and save the rest in output allocation? I'm new to Renderscript and most of the kernel function tends to work on the entire input data set.


Solution

  • Yes, use the LaunchOptions API to limit the rectangle that you launch over:

    Script.LaunchOptions lo;
    lo.setX(10, 100);
    lo.setY(5, 20);
    kernel.forEach(in, out, lo);
    

    https://developer.android.com/reference/android/renderscript/Script.LaunchOptions.html