我可以得到兩個獨立的內部函數,但不能在ScriptGroup中一起工作。我發現如何使用Script Group的文檔非常稀疏。如何讓Android Render Script Group工作?
這裏是我的代碼:
mRS = RenderScript.create(getActivity());
mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT |
Allocation.USAGE_GRAPHICS_TEXTURE|
Allocation.USAGE_SHARED
);
mOutAllocation = Allocation.createFromBitmap(mRS, mBitmapOut,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT |
Allocation.USAGE_SHARED);
ScriptIntrinsicColorMatrix gray = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
gray.setGreyscale();
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
blur.setRadius(20.f);
blur.setInput(mInAllocation);
//gray.forEach(mInAllocation, mOutAllocation);
blur.forEach(mOutAllocation);
mOutAllocation.copyTo(mBitmapOut);
灰色和模糊的工作。然後我試着把它們放在一起,結果是空白的。代碼:
// gray.forEach(mInAllocation, mOutAllocation);
// blur.forEach(mOutAllocation);
// mOutAllocation.copyTo(mBitmapOut);
ScriptGroup.Builder builder = new ScriptGroup.Builder(mRS);
builder.addKernel(gray.getKernelID());
builder.addKernel(blur.getKernelID());
builder.addConnection(mInAllocation.getType(), gray.getKernelID(), blur.getKernelID());
ScriptGroup group = builder.create();
group.setInput(gray.getKernelID(), mInAllocation);
group.setOutput(blur.getKernelID(), mOutAllocation);
group.execute();
mOutAllocation.copyTo(mBitmapOut);
我試過了,這沒有什麼區別。我的意思是將兩個rs內聯添加到腳本組中,然後在圖像視圖中不顯示輸出。我在這裏上傳了我的測試項目:https://github.com/laoyang/rstest,如果你想看看。謝謝! –
細化我的分析。往上看。 –
謝謝!你是對的,我改變了順序,讓模糊成爲第一個,並設定了它的輸入。腳本組正在工作。所以我認爲渲染腳本仍然不成熟... –