【问题标题】:Bitmap loader not displaying color properly位图加载器未正确显示颜色
【发布时间】:2016-07-24 03:36:01
【问题描述】:

我需要将位图图像转换为纹理。因此,我正在编写用于解析位图的 c 代码。我能够解析位图 rgb 数据并显示它。但是颜色不正确。 它的 32 位图像。(ARGB)

int pixels = width * height * 4;
unsigned char* data = new unsigned char[pixels];
const int row = width * 4;
const int colomn = height;
unsigned char* datarow = new unsigned char[row];
unsigned char data1[pixels];
#if 1
fseek(f, 54,SEEK_SET);
fread(data, sizeof(unsigned char), pixels, f);

 fclose(file);
#endif
for(int i = 0; i < colomn; i++) {
    for(int j = 0; j < row; j++)
    {
            data1[j+i*row] = data[j+((colomn-i)*row)];
    }
}

【问题讨论】:

    标签: c bitmap bitmapdata


    【解决方案1】:

    您可能是最容易忘记图像由扫描线组成并且扫描线是 32 位对齐的人。所以你简单的行/列计算不起作用。

    请参阅Dealing with padding in a BMP file in C 了解如何使用扫描线。

    【讨论】:

      猜你喜欢
      • 2015-11-23
      • 2022-11-22
      • 2012-01-17
      • 1970-01-01
      • 2011-08-06
      • 2012-09-30
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多