Android RenderScript 浅谈

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

前言

     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);
		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值