BMP图像加载实例(C语言)
来源:互联网 发布:玖富微理财网络借贷 编辑:程序博客网 时间:2024/04/21 00:30
bmp图像常被称为位图,这实际是对位图的误解,具体可见opengl superbible中对图像的说明。
代码如下:
#include <stdio.h>#include <stdlib.h>#include <GL/glew.h>#ifdef _APPLE_#include <glut/glut.h>#else#define FREEGLUT_STATIC#include <GL/glut.h>#endifGLuint loadBMP_custom(const char * imagepath);// Data read from the header of the BMP fileunsigned char header[54]; // Each BMP file begins by a 54-bytes headerunsigned int dataPos; // Position in the file where the actual data beginsunsigned int width, height;unsigned int imageSize; // = width*height*3// Actual RGB dataunsigned char * data;int main(int argc, char **argv){FILE * file = fopen("1.bmp", "rb");if (!file){printf("Image could not be openedn"); return 0;}if ( fread(header, 1, 54, file)!=54 ){ // If not 54 bytes read :problemprintf("Not a correct BMP filen");return 0;}if ( header[0]!='B' || header[1]!='M' ){printf("Not a correct BMP filen");return 0;}// Read ints from the byte arraydataPos = *(int*)&(header[0x0A]);imageSize = *(int*)&(header[0x22]);width = *(int*)&(header[0x12]);height = *(int*)&(header[0x16]);printf("%d \t %d \t %d \t %d \n", dataPos, imageSize, width, height);printf("%d \t %d \t %d \t %d \n", &(header[0x0A]),&(header[0x22]),&(header[0x12]), &(header[0x16]));printf("%d \t %d \t %d \t %d \n", &(header[0x0A]),&(header[0x22]),(int *)&(header[0x12]), &(header[0x16]));printf("%d\t %d\t",*(int*)&(header[0x12]), *(char*)&(header[0x16]));getchar();return 0;}
使用的图像:
测试结果如下:
1 0
- BMP图像加载实例(C语言)
- C语言处理BMP图像
- C语言读写BMP图像
- C语言读取BMP图像数据(转)
- 标题:C语言处理BMP图像
- 纯c语言读取BMP图像
- C语言读取BMP图像到数组,BMP图片格式
- symbian Grid图像动态转换加载图像(jpg,bmp)
- C语言实现bmp图像的平移操作
- 用C语言在桌面上创建一副bmp图像
- C语言实现BMP图像的写入与图像的清空(256色灰度图)
- C语言构建BMP文件(一)
- C 语言bmp 解析
- BMP图像生成 纯C
- 编程学C#(2):BMP图像处理
- [转载]symbian Grid图像动态转换加载图像(jpg,bmp)
- C语言查看BMP格式图片头(bmpHeader.c)
- 实现图像格式的转换代码 C语言实现 RGB565转BMP图像
- Linux chkconfig命令使用详解
- js获得当前时区夏令时发生和终止的时间
- Linux crontab计划任务应用
- Codeforces Round 231 D 两次二分
- [leet code] Edit Distance
- BMP图像加载实例(C语言)
- 关于我为什么要写博文?
- Spring的Quartz定时机制
- Maximum Depth of Binary Tree -- LeetCode
- Minimum Depth of Binary Tree -- LeetCode
- 互斥与同步(一)
- ubuntu系统 调整屏幕分辨率
- linux bind 配置详解
- Minimum Window Substring