1
我正在RenderScript中使用一個簡單的腳本。我必須修改位圖上像素的RGBA值。經過多次嘗試,我發現Alpha通道不會被修改。RenderScript不會修改Alpha通道? [Android]
我做了一些研究,我發現this old question,但我不明白如何以及爲什麼發生這種情況。腳本中是否有正確的modiphy Alpha通道?
這裏是我的代碼一個精簡版:
Java方面:
Allocation img= Allocation.createFromBitmap(encodeRS, bmp,Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
的renderScript方:
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
uchar r= (in.r) & 0xFC;
uchar g= (in.g) & 0xFC;
uchar b= (in.b) & 0xFC;
uchar a= (in.a) & 0xFC;
return (uchar4) {r,g,b,a};
}
我也試圖與存儲結合,但結果都是一樣的:
void root(uchar4* in, uint32_t x, uint32_t y) {
uchar r= (in->r) & 0xFC;
uchar g= (in->g) & 0xFC;
uchar b= (in->b) & 0xFC;
uchar a= (in->a) & 0xFC;
in->r= r;
in->g= g;
in->b= b;
in->a= a;
}
然後我從java端copyTo(在forEach之後),但alpha通道自動設置爲255。
img.copyTo(bmp);
無論如何感謝您的支持。
- 更新1:
我忘了提,我得到的位圖從一個文件getAbsolutePath()這樣的:
Bitmap bmp= BitmapFactory.decodeFile(imgFile.getAbsolutePath());
您想要| Allocation.USAGE_SHARED,因爲它會減少大多數位圖上的副本數量。 –
感謝這兩個。我從SDCARD的路徑中獲取位圖,如下所示: Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 如果這會導致問題,我將檢查使用ARGB_8888創建的通用位圖。 – gabrielication