我想進入渲染腳本,並對分配使用感到困惑。幾乎所有的例子表明未來的算法:從位圖Renderscript分配
- 創建In和Out位圖
- 從位圖和註銷相應
- 配置腳本創建和註銷分配和輸出分配進行的forEach方法
- 拷貝結果進位圖使用CopyTo方法
類似的東西:
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lena);
Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());
Allocation allocationIn = Allocation.createFromBitmap(renderScript, srcBitmap);
Allocation allocationOut = Allocation.createFromBitmap(renderScript, dstBitmap);
scriptColorMatrix.setGreyscale();
scriptColorMatrix.forEach(allocationIn, allocationOut);
//no difference after removing this line
allocationOut.copyTo(dstBitmap);
imagePreview.setImageBitmap(dstBitmap);
這工作,但它也有效,即使我省略步驟4通過去除:
allocationOut.copyTo(dstBitmap);
讓我們去進一步和較低的亮度灰度後:
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lena);
Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());
Allocation allocationIn = Allocation.createFromBitmap(renderScript, srcBitmap);
Allocation allocationOut = Allocation.createFromBitmap(renderScript, dstBitmap);
scriptColorMatrix.setGreyscale();
scriptColorMatrix.forEach(allocationIn, allocationOut);
//reset color matrix
scriptColorMatrix.setColorMatrix(new Matrix4f());
//adjust brightness
scriptColorMatrix.setAdd(-0.5f, -0.5f, -0.5f, 0f);
//Performing forEach vise versa (from out to in)
scriptColorMatrix.forEach(allocationOut, allocationIn);
imagePreview.setImageBitmap(srcBitmap);
不久描述上面的代碼中,我們從In分配到Out 1執行灰度collor矩陣,並向後調整亮度。我從來沒有調用過copyTo方法,但最後我在srcBitmap中得到了結果,它是正確的。
這不是結束。讓我們更深入。我將只留下一個位圖和一個分配:
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lena);
Allocation allocationIn = Allocation.createFromBitmap(renderScript, srcBitmap);
scriptColorMatrix.setGreyscale();
scriptColorMatrix.forEach(allocationIn, allocationIn);
//reset color matrix
scriptColorMatrix.setColorMatrix(new Matrix4f());
//adjust brightness
scriptColorMatrix.setAdd(-0.5f, -0.5f, -0.5f, 0f);
scriptColorMatrix.forEach(allocationIn, allocationIn);
imagePreview.setImageBitmap(srcBitmap);
的結果是一樣的...
任何人都可以解釋爲什麼它會發生,在哪裏使用CopyTo從哪裏我可以使用目標沒有它的位圖?
非常感謝!這是非常明確的答案 – VinSmile
你非常歡迎!我很高興你發現它有幫助! –