我正在接收ARGB8888格式的位圖,但我需要通過一些只接受RGB565的算法來處理它。我想使用Renderscript將此位圖轉換爲新格式,但似乎分配和分配輸出應該相等(或兼容)。 bitmapIn是類型ARGB_8888的和bitmapOut是類型的RGB_565Renderscript從ARGB8888轉換到RGB565
所致:android.renderscript.RSIllegalArgumentException:分配一種是PIXEL_RGBA,4個字節類型UNSIGNED_8,通過位圖是RGB_565
爪哇:
public void convert(final Bitmap bitmapIn, Bitmap bitmapOut)
{
mInAllocation = Allocation.createFromBitmap(mRS, bitmapIn, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
Type.Builder tb = new Type.Builder(mRS, Element.RGB_565(mRS)).setX(bitmapIn.getWidth()).setY(bitmapOut.getWidth());
mOutAllocation = Allocation.createTyped(mRS, tb.create());
// Call custom method (not forEach_root) so we can have uchar4 in and uchar3 out
mScript.forEach_convert(mInAllocation, mOutAllocation);
mOutAllocation.copyTo(bitmapOut);
}
的renderScript:
// Convert to RGB565 by quantizing the individual channels
void convert(const uchar4* v_in, uchar3* v_out)
{
v_out->x = v_in->x >> 3;
v_out->y = v_in->y >> 2;
v_out->z = v_in->z >> 3;
}
請注意,如果我將兩個位圖ARGB_8888和convert()都工作在兩個uchar4 *上(並且只是複製alpha(w)通道,那麼我會看到該位圖被更改。
我知道565等於16位,所以實際上它更可能是一個uchar2,但它也與類型中的分配不兼容。
在Renderscript中如何做這種類型的轉換?
我仍然得到類型轉換錯誤:RSRuntimeException:類型不匹配與U16! RS函數:ushort __attribute __((kernel))root(uint32_t x,uint32_t y){return 65535; } Java:在分配爲RGBA_8888時,輸出爲RGB_565,通過mScript.set_in_allocation(mAllocationIn)綁定; – BCL 2013-04-04 17:33:14