【问题标题】:android RGB565 format bitmapandroid RGB565格式位图
【发布时间】:2020-07-14 22:45:37
【问题描述】:

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

createBitmap(width, height, 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;
}

【问题讨论】:

  • 我看不到任何限制为五位或扩展到六位的内容。 ——
  • 绿色在 RGB 中有 6 位,但在 BRG 中有 5 位。所以你必须适应。
  • 如何在机器人屏幕上显示图像?您使用什么库/ies 和方法?我本来希望图书馆在必要时进行所需的色彩空间转换
  • @blackapps 如何适应 BRG 中的 5 位绿色位?
  • @Joni 我使用了一个 protobuf 库,它只需要一个 ByteString 的图像。没有自动转换。

标签: java android bitmap


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2013-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多