前言
RenderScript是一个Google出品的,在Android平台上的并行计算框架,官方的简介是说RenderScript运行时可在设备上提供的多个处理器(如多核 CPU 和 GPU)间并行调度工作。在日常Android开发中,RenderScript主要用于图像处理。比如对图片做高斯模糊等,都可以用RenderScript处理。

内容来自RenderScript 概览
扯淡的文档说明, 加上这玩意要被舍弃了, 觉得有点可惜

内容来自从 RenderScript 迁移
使用
总的来说,RenderScript能干的事情很多,但有限。常见用于处理Bitmap的效果、转换。
如(参考RenderScript Intrinsics Replacement Toolkit):
- blend,
- blur,
- color matrix,
- convolve,
- histogram and histogramDot,
- LUT (lookup table) and LUT 3D,
- resize, and YUV to RGB.
uchar4 RS_KERNEL invert(uchar4 in, uint32_t x, uint32_t y) {
uchar4 out = in;
out.r = 255 - in.r;
out.g = 255 - in.g;
out.b = 255 - in.b;
return out;
}
对应java调用代码
public static Bitmap invert(Context context, Bitmap bm){
Bitmap bmOut = Bitmap.createBitmap(bm);
RenderScript RS = RenderScript.create(context);
ScriptC_singlesource script = new ScriptC_singlesource(RS);
//Allocation inputAllocation = Allocation.createFromBitmapResource(
// RS, getResources(), R.drawable.image);
Allocation inputAllocation = Allocation.createFromBitmap(RS, bm);

RenderScript是Google为Android平台设计的一个并行计算框架,常用于图像处理如高斯模糊。尽管有被替代的趋势,但其仍可用于Bitmap的多种效果处理,如blend、blur和colormatrix等。文章展示了如何使用RenderScript进行Bitmap的反色操作,并探讨了如何处理int[]和byte[]数据,以及使用uchar4进行颜色操作。示例代码演示了创建和使用RenderScriptAllocation的方法。
最低0.47元/天 解锁文章
6466

被折叠的 条评论
为什么被折叠?



