【问题标题】:Extracting pixcel color values in byte[] from BItmap从 BItmap 中提取 byte[] 中的像素颜色值
【发布时间】:2016-09-21 09:59:38
【问题描述】:

背景

我正在编写一个简单的应用程序,其中应用程序从位图中以 RGB_565 格式提取像素颜色并通过 BLE 将其发送到蓝牙设备

我得到了 argb 格式的 int[] 颜色,我想要 RGB_565 格式 所以我从Color.red(-10267343) 提取了红色、绿色、蓝色,其中-10267343 是我从getPixel(x,y) 获得的像素的颜色

我明白了

red : 99
green : 85
blue : 99 //from the above color value -10267343

我的问题是如何在两个字节中添加这些红色、绿色、蓝色

我需要这种格式|R|R|R|R|R|G|G|G|G|G|G|B|B|B|B|B|

目前为止我试过这个方法

byte[] colorToByte(int c){
  int r = (c >> 16) & 0xFF;
  int g = (c >> 8)  & 0xFF;
  int b =  c        & 0xFF;
  return new byte[]{(byte)((r&248)|g>>5),(byte)((g&28)<<3|b>>3)};
}

正如这个答案中所建议的How to correctly convert from rgb565 to rgb888

我也试过这个答案,但没有运气Java image conversion to RGB565

有什么办法可以解决这个问题吗?任何帮助表示赞赏

【问题讨论】:

    标签: android android-bitmap


    【解决方案1】:
    private static byte[] colorToByte(int c){
            int rgb = c;
            int blue = rgb & 0xFF;
            int green = (rgb >> 8) & 0xFF;
            int red = (rgb >> 16) & 0xFF;
    
            int r_565 = red >> 3;
            int g_565 = green >> 2;
            int b_565 = blue >> 3;
            int rgb_565 = (r_565 << 11) | (g_565 << 5) | b_565;
    
            return new byte[]{(byte) ((rgb_565 >> 8) & 0xFF), (byte) (rgb_565 & 0xFF)};
    
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 2013-07-21
      • 2019-07-27
      • 1970-01-01
      • 2019-02-16
      • 2017-09-18
      • 2014-12-06
      相关资源
      最近更新 更多