有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 安卓 RGB565格式位图

我正在尝试在Anki Vector robot上显示图像。 我的Android应用程序从画布上绘制位图,然后使用“createBitmap”方法将其转换为RGB_565格式。因为这里的显示指定为RGB565: https://vector.ikkez.de/generated/anki_vector.screen.html#module-anki_vector.screen

创建位图(宽度、高度、Bitmap.Config.RGB_565)

结果似乎很成功,但颜色通道不正确

RGB像BRG一样被订购。 作为解决办法,我相应地交换了频道。 但现在橙色和黄色似乎互换了。 当我画橙色时,显示屏显示黄色。当我画黄色时,它显示橙色。 有什么问题吗

对于交换通道,我使用了以下代码:

public Bitmap swapC(Bitmap srcBmp) {

    int width = srcBmp.getWidth();
    int height = srcBmp.getHeight();

    float srcHSV[] = new float[3];
    float dstHSV[] = new float[3];

    Bitmap dstBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            int pixel = srcBmp.getPixel(col, row);
            int alpha = Color.alpha(pixel);
            int redC = Color.red(pixel);
            int greenC = Color.green(pixel);
            int blueC = Color.blue(pixel);
            dstBitmap.setPixel(col, row, Color.argb(alpha,blueC,redC,greenC));
        }
    }

    return dstBitmap;
}

共 (1) 个答案

  1. # 1 楼答案

    我使用了一种变通方法作为解决方案;将颜色通道值除以8:

    public Bitmap swapC(Bitmap srcBmp) {
    
        int width = srcBmp.getWidth();
        int height = srcBmp.getHeight();
    
        float srcHSV[] = new float[3];
        float dstHSV[] = new float[3];
    
        Bitmap dstBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    
        for (int row = 0; row < height; row++) {
            for (int col = 0; col < width; col++) {
                int pixel = srcBmp.getPixel(col, row);
                int alpha = Color.alpha(pixel);
                int redC = Color.red(pixel);
                int greenC = Color.green(pixel);
                int blueC = Color.blue(pixel);
                dstBitmap.setPixel(col, row, Color.argb(alpha,blueC/8,redC/8,greenC/8));
            }
        }
    
        return dstBitmap;
    }