链表的头指针 front 指向新插入的节点 s 的下一个节点,而 s 的指针意思指向原来的头节点是什么
时间: 2023-05-23 16:01:00 浏览: 174
在C语言中打开图片需要使用图像处理库。常用的图像处理库包括OpenCV、ImageMagick、FreeImage等。以下是使用OpenGL库打开并显示一张bmp图片的代码(需要安装OpenGL和GLUT库):
```
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
int width = 500, height = 500;
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
int main(int argc, char** argv) {
FILE* fp;
char fname[] = "image.bmp";
unsigned char header[54];
unsigned int dataPos, size, width, height;
unsigned char* data;
fp = fopen(fname, "rb");
fread(header, sizeof(unsigned char), 54, fp);
dataPos = *(int*)&header[10];
size = *(int*)&header[34];
width = *(int*)&header[18];
height = *(int*)&header[22];
data = (unsigned char*)malloc(sizeof(unsigned char) * size);
fread(data, sizeof(unsigned char), size, fp);
fclose(fp);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(width, height);
glutCreateWindow(fname);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glRasterPos2i(0, 0); // set position of the image
glDrawPixels(width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, data); // draw image
glutDisplayFunc(display);
glutMainLoop();
free(data);
return 0;
}
```
该程序读取位图文件image.bmp并使用OpenGL库绘制该图片。可以将该程序保存为image.c并在命令行中执行:
```
gcc -o image image.c -lGL -lGLU -lglut
./image
```
即可打开该图片。
阅读全文