Android 图片处理RenderScript Intrins
该Toolkit
提供了一系列高性能图像处理功能 如模糊、混合和调整大小。已弃用的RenderScript Intrinsics
函数的完美替代品。

该ToolKit
包提供了一个C++
和一个Java
/Kotlin
接口。它被打包为Android
可以添加到项目中的库。
这些函数在CPU
上执行多线程。他们利用霓虹灯/AdvSimd ,在Arm
处理器和英特尔的SSE
上。
与RenderScript Intrinsics
相比,该Toolkit
使用更简单,当在CPU
上执行时,速度是RenderScript Intrinsics
的两倍。但是,
RenderScript
内部函数允许更大的灵活性 支持的分配类型。该Toolkit
不支持浮动分配;
大多数函数支持字节数组和位图。
您应该实例化Toolkit
一次,并在整个应用程序中重用它。
在实例化时,Toolkit
会创建一个线程池,用于处理所有函数。
您可以通过构造函数限制Toolkit
使用的池线程数。池线程中在完成任何未决工作后,一旦Toolkit
被销毁,就会被销毁。
此库是线程安全的。您可以从不同的池线程调用方法。这些功能将: 按顺序执行。
Gradle引入
jitpack远程仓库
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
引用
dependencies {
implementation 'com.github.Neo-Turak:renderscript-toolkit:v0.8'
}
实例中使用的图片:


混合模式
使用方法:ToolKit.blend() 方法,重载2个。
val testImage1 = BitmapFactory.decodeResource(resources, R.drawable.img800x450b)
val testImage2 = BitmapFactory.decodeResource(resources, R.drawable.img800x450a)
Toolkit.blend(BlendingMode.ADD, testImage1, testImage2)
findViewById<ShapeableImageView>(R.id.siv).setImageBitmap(testImage2)
效果:

高斯模糊
使用方法: Toolkit.blue() 请注意取值范围(1-5)
val testImage1 = BitmapFactory.decodeResource(resources, R.drawable.img800x450b)
val result=Toolkit.blur(testImage1,3)
findViewById<ShapeableImageView>(R.id.siv).setImageBitmap(result)
效果:

颜色矩阵滤镜
使用方法:Toolkit.colorMatrix()
盲卷积
使用方法:Toolkit.convolve()
val testImage1 = BitmapFactory.decodeResource(resources, R.drawable.img800x450b)
// val testImage2 = BitmapFactory.decodeResource(resources, R.drawable.img800x450a)
val result = Toolkit.convolve(
testImage1,
floatArrayOf(1F, 1F, 1f, 1f, 1f, 1f, 1f, 1f, 1f)
)
findViewById<ShapeableImageView>(R.id.siv).setImageBitmap(result)
效果:

直方图和直方图点
使用方法:Toolkit.histogram()直方图
Toolkit.histogramDot()直方图点
LUT 和 LUT 3D
使用方法:Toolkit.lut() 和Toolkit.loot3d()
val testImage1 = BitmapFactory.decodeResource(resources, R.drawable.img800x450b)
// val testImage2 = BitmapFactory.decodeResource(resources, R.drawable.img800x450a)
val lookupTable=LookupTable()
lookupTable.blue= byteArrayOf(10)
val result = Toolkit.lut(
testImage1,
lookupTable
)
findViewById<ShapeableImageView>(R.id.siv).setImageBitmap(result)
效果:

调整大小
使用方法:Toolkit.resize()
val testImage1 = BitmapFactory.decodeResource(resources, R.drawable.img800x450b)
// val testImage2 = BitmapFactory.decodeResource(resources, R.drawable.img800x450a)
val result = Toolkit.resize(
testImage1,
100,50
)
findViewById<ShapeableImageView>(R.id.siv).setImageBitmap(result)
效果:

YUV to RGB
使用方法:Toolkit.yuvToRgb() 等等。