我在尝试运行renderscript
以反转图像时收到错误消息
Process 'command '/home/sandesh/Applications/AndroidStudio/Android/Sdk/build-tools/29.0.2/llvm-rs-cc'' finished with non-zero exit value 1
爪哇:
RenderScript rs = RenderScript.create(context);
ScriptC_clone scriptC_clone = new ScriptC_clone(rs);
Allocation inputAllocation = Allocation.createFromBitmapResource(
rs, context.getResources(), R.drawable.image_1);
Allocation outputAllocation = Allocation.createTyped(
rs, inputAllocation.getType(),
Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_OUTPUT);
scriptC_clone.invoke_process(inputAllocation, outputAllocation);
克隆.rs:
#pragma version(1)
#pragma rs java_package_name(com.example.clone)
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;
}
void process(rs_allocation inputImage, rs_allocation outputImage) {
const uint32_t imageWidth = rsAllocationGetDimX(inputImage);
const uint32_t imageHeight = rsAllocationGetDimY(inputImage);
rs_allocation tmp = rsCreateAllocation_uchar4(imageWidth, imageHeight);
rsForEach(invert, inputImage, tmp);
}
梯度:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
defaultConfig {
applicationId "com.example.clone"
minSdkVersion 22
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/']
renderscript.srcDirs =['src/main/rs', 'src/main/rs/']
} }
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation project(path: ':openCVLibrary348')
implementation 'com.google.android.material:material:1.0.0'
}