【问题标题】:Android - converting byte rgb_565 array into argb or rgb arrayAndroid - 将字节 rgb_565 数组转换为 argb 或 rgb 数组
【发布时间】:2011-01-04 05:01:57
【问题描述】:

我在字节 rgb_565 数组中有图片数据,我想以有效的方式将其转换为 argb 数组。现在我只找到了一种(有点慢)方法:

Bitmap mPhotoPicture = BitmapFactory.decodeByteArray(imageData, 0 , imageData.length);

其中imageData 是我在rgb_565 中的byte[] 数组,然后:

int pixels[] = new int[CameraView.PICTURE_HEIGHT*CameraView.PICTURE_WIDTH];
mPhotoPicture.getPixels(pixels, 0,PICTURE_WIDTH, 0, 0, PICTURE_WIDTH, PICTURE_HEIGHT);

关键是我相信创建一个Bitmap 对象是严格的,在这种情况下没有必要。还有其他更快的方法可以将 rgb_565 数组转换为 argb 数组吗?

我需要这个,因为在 rgb_565 数组上进行图像处理似乎有点烦人。或者也许没那么难?

【问题讨论】:

    标签: android image-processing image-manipulation


    【解决方案1】:

    你为什么不手动做呢?根据我的经验,一张桌子是最快的:

    C代码:

    static unsigned char rb_table[32];
    static unsigned char g_table[64];
    
    void init (void)
    {
      // precalculate conversion tables:
      int i;
      for (i=0; i<32; i++)
        rb_table[i] = 255*i/31;
      for (i=0; i<64; i++)
        g_table[i] = 255*i/63;
    }
    
    
    void convert (unsigned int * dest, unsigned short * src, int n)
    {
      // do bulk data conversion from 565 to rgb32
      int i;
    
      for (i=0; i<n; i++)
      {
        unsigned short color = src[i];
    
        unsigned int red   = rb_table[(color>>11)&31]<<16;
        unsigned int green = g_table[(color>>5)&63]<<8;
        unsigned int blue  = rb_table[color&31];
    
        dest[i] = red|green|blue;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      • 2016-03-02
      • 2013-04-12
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多