我想读取 RGB 值,但我得到的只是 0 - 255 个灰度值



我一直在读取双指针数组中的图像文件。

    BMP(char *fn, int no )
{
    ifstream in(fn,ios::binary);
    in.read((char*)&header,sizeof(header));
    width=(int)(header[21]<<24|header[20]<<16|header[19]<<8|header[18]);
    height=(int)(header[25]<<24|header[24]<<16|header[23]<<8|header[22]);
    cout<<"Height:"<<height<<" Width:"<<width<<'n';
    in.read((char*)&plt,sizeof(plt));
    clrs=new unsigned char[width*height];
    in.read((char*)clrs,width*height);
    in.close();
    rollNo = no;
}

我面临的问题是,它根据灰度读数读取从 0 到 255 的颜色值。

    void showOne ()
{
    for ( int i = 0 ; i < width*height ; i++ )
    {
        int val1 = clrs[i];
        cout << "tt index : " << i << " :tt" << val1 << endl;
    }
}

谁能告诉我如何将该读数转换为十六进制值,或者任何其他方法才能区分 RGB 值?

当图像编码每像素 24 位数据(真彩色(时,标头的字段 biBitCount 设置为 24(您必须检查(。

然后像素数据由三元组 BGR 字节组成。根据要对颜色值执行的操作,将保留原始字节或将它们转换为其他表示形式,三三个。

最新更新