我收到的位图格式为 ARGB8888,但我需要通过一些只接受RGB565的算法进行处理。我想使用 Renderscript 将这个位图转换为新格式,但似乎分配进和分配出的大小应该是相等的(或兼容的)。
bitmapIn 类型为 ARGB_8888, bitmapOut 类型为 RGB_565。
Renderscript:
请注意,如果我将两个位图都设置为ARGB_8888,并在uchar4*上工作并仅复制alpha(w)通道,则会看到位图被修改。
我知道565等于16位,因此实际上更可能是一个uchar2,但它也与类型中的分配不兼容。
如何在Renderscript中执行此类型转换?
导致此问题的原因是:android.renderscript.RSIllegalArgumentException: 分配类型为 PIXEL_RGBA,类型为 UNSIGNED_8 的 4 字节,传递的位图却是 RGB_565
Java:
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,并在uchar4*上工作并仅复制alpha(w)通道,则会看到位图被修改。
我知道565等于16位,因此实际上更可能是一个uchar2,但它也与类型中的分配不兼容。
如何在Renderscript中执行此类型转换?