Bitmap Channels order different in Android

梦想的初衷 提交于 2019-12-04 19:06:31

You can switch the colors like this:

(This code does not origin from me, unfortunately I forgot where I found it, so credit goes somewhere else)

private Bitmap m_encodingBitmap         = null;
private Canvas m_canvas                 = null;
private Paint m_paint                   = null;    
private final float[] m_bgrToRgbColorTransform  =
    {
        0,  0,  1f, 0,  0, 
        0,  1f, 0,  0,  0,
        1f, 0,  0,  0,  0, 
        0,  0,  0,  1f, 0
    };
private final ColorMatrix               m_colorMatrix               = new ColorMatrix(m_bgrToRgbColorTransform);
private final ColorMatrixColorFilter    m_colorFilter               = new ColorMatrixColorFilter(m_colorMatrix);

...

try{

FREBitmapData as3Bitmap = (FREBitmapData)args[0];
as3Bitmap.acquire();
m_encodingBitmap    = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
m_canvas        = new Canvas(m_encodingBitmap);
m_paint         = new Paint();
m_paint.setColorFilter(m_colorFilter);

m_encodingBitmap.copyPixelsFromBuffer(as3BitmapBytes);
as3Bitmap.release();
//
// Convert the bitmap from BGRA to RGBA.
//
m_canvas.drawBitmap(m_encodingBitmap, 0, 0, m_paint);

...

}

Hope that helps ... Timm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!