写了一个贴图的程序,程序运行后出现错误 :unknown dib file format


问题解决了,是DIB问题,我采用位图位数不统一,有8位,也有24位,把8位改为24位后又能贴

AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image { FILE *File=NULL; // File Handle

if (!Filename) // Make Sure A Filename Was Given { return NULL; // If Not Return NULL }

File=fopen(Filename,"r"); // Check To See If The File Exists

if (File) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer }

return NULL; // If Load Failed Return NULL }

int LoadGLTextures() // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture

memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if (TextureImage[0]=LoadBMP("Data/Ne.bmp")) { Status=TRUE; // Set The Status To TRUE

glGenTextures(1, &texture[0]); // Create The Texture

我把Nehe第六课的代码中的图片换成了自己的头像,然后出现了这个问题。

问了别人,才知道我直接把jpg的格式改为bmp格式就加载上去是好傻的事情。

应该使用画图板打开png或者jpg,然后另存为bmp(24位)。

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,以下是一个简单的 BMP 文件读取并输出信息的程序示例: ```c #include <stdio.h> #include <stdint.h> // 定义 BMP 文件头结构体 #pragma pack(push, 1) typedef struct { uint16_t type; // 文件类型,必须为 BM uint32_t size; // 文件大小,单位为字节 uint16_t reserved1; // 保留字段1 uint16_t reserved2; // 保留字段2 uint32_t offset; // 数据偏移量,即 BMP 数据起始位置相对于文件头的偏移量 uint32_t dib_size; // DIB 数据结构大小,Windows BMP 文件中此值为 40 int32_t width; // 图像宽度,单位为像素 int32_t height; // 图像高度,单位为像素 uint16_t planes; // 位面数,必须为 1 uint16_t bpp; // 每个像素的位数,即色深 uint32_t compression; // 压缩方式,0 表示不压缩 uint32_t image_size; // 图像数据大小,单位为字节,如果不压缩则为 0 int32_t x_ppm; // 水平分辨率,单位为像素每米 int32_t y_ppm; // 垂直分辨率,单位为像素每米 uint32_t colors; // 调色板颜色数,如果为 0 表示使用默认值 uint32_t important; // 重要颜色数,如果为 0 表示所有颜色都重要 } bmp_file_header_t; #pragma pack(pop) int main() { FILE *file; bmp_file_header_t header; // 打开 BMP 文件 if ((file = fopen("test.bmp", "rb")) == NULL) { printf("Failed to open the file.\n"); return 1; } // 读取 BMP 文件头 if (fread(&header, sizeof(bmp_file_header_t), 1, file) != 1) { printf("Failed to read the file header.\n"); fclose(file); return 1; } // 输出 BMP 文件信息 printf("BMP type: %c%c\n", (char)(header.type & 0xFF), (char)(header.type >> 8)); printf("File size: %d bytes\n", header.size); printf("Data offset: %d bytes\n", header.offset); printf("Width: %d pixels\n", header.width); printf("Height: %d pixels\n", header.height); printf("Bit per pixel: %d\n", header.bpp); // 关闭 BMP 文件 fclose(file); return 0; } ``` 这个程序可以读取 BMP 文件头,并输出文件的类型、大小、数据偏移量、图像宽度和高度、像素位数等信息。注意,这个程序只能读取 Windows BMP 文件的头部信息,如果要读取完整的 BMP 文件,还需要根据文件头中的信息读取图像数据区。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值