0
我想鏈兩個Renderscripts:ScriptIntrinsicBlur和ScriptIntrinsicColorMatrix。
我想模糊和圖像,然後將顏色過濾器應用到它。鏈2 Renderscript Intrinsics:模糊和ColorMatrix
這裏是我當前的代碼(我嘗試了許多不同的實現方式,包括ScriptGroups,我不能去上班:
final ScriptIntrinsicBlur scriptBlur = ScriptIntrinsicBlur.create(
mRenderScript,
Element.U8_4(mRenderScript));
final Allocation input = Allocation.createFromBitmap(mRenderScript,
bmp);
Bitmap blurOutBitmap = bmp.copy(bmp.getConfig(), true);
final Allocation output = Allocation.createFromBitmap(
mRenderScript, blurOutBitmap);
scriptBlur.setRadius(mBlur_Radius);
scriptBlur.setInput(input);
scriptBlur.forEach(output);
bmp.recycle();
output.copyTo(blurOutBitmap);
mRenderScript.finish();
final ScriptIntrinsicColorMatrix scriptColor = ScriptIntrinsicColorMatrix
.create(mRenderScript, Element.U8_4(mRenderScript));
/** for a first test, I am using a simple blue filter **/
Matrix3f mat = new Matrix3f(new float[] {
1, 0, 1,
0, 1, 1,
0, 0, 1
});
scriptColor.setColorMatrix(mat);
final Allocation colorInput = Allocation.createFromBitmap(mRenderScript,
blurOutBitmap);
Bitmap outBitmap = bmp.copy(blurOutBitmap.getConfig(), true);
final Allocation colorOutput = Allocation.createFromBitmap(
mRenderScript, outBitmap);
scriptColor.forEach(colorInput, colorOutput);
blurOutBitmap.recycle();
colorOutput.copyTo(outBitmap);
displayBitmap(outBitmap);
這段代碼產生的圖像非常難看的圖像(平行紅線)和如果我嘗試使用ScriptGroup相反它只是崩潰。
是否有人用的renderScript的經驗可以幫助我破譯爲什麼?因爲有關於該主題很少樣品或文檔,我堅持努力隨機修改。
你嘗試過沒有調用'bmp.recycle()'後,你的模糊內在運行?該調用將釋放位圖對象後面的任何本機緩衝區,但稍後在爲濾色器設置「outBitmap」時再次使用該對象。 –
@LarrySchiefer嗯,我可能會更聰明才能在完成後回收。謝謝 !其實,我剛剛找到了一個讓這個小組工作的方法。看起來這個ScriptGroup + Intrinsic案例中存在一個錯誤 – Teovald