Linux绘制图形

linux下可以通过打开/dev/fb0设备对界面绘图。但在打开/dev/fb0设备文件前,需要使linux进入以像素为单位的图形模式,而不是在字符为单位的字符模式下,不然打开dev/fb0会提示错误。(图形模式下一样存在字符界面,不过字符界面的写操作不在是往显存写字符,而是往显存写像素,这是由内核处理的不需我们处理)关于如何进入图形模式,可以参考(http://blog.csdn.net/pk_20140716/article/details/46807921)

打开/dev/fb0设备后,使用mmap映射入自己的程序空间,便可对整个图形界面进行操作。在这里获取映射空间就获取了整个屏幕,而不是在xwindow里获取的屏幕空间,可以说/dev/fb0是比xwindow更底层的处理。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用C语言和一些图形库来绘制折线Linux系统上。在Linux中,常用的图形库包括Xlib、GTK+、Qt等。下面是一个使用Xlib库绘制折线的简单示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <X11/Xlib.h> #define WIDTH 500 #define HEIGHT 300 void drawLine(Display *display, Window window, GC gc, int x1, int y1, int x2, int y2) { XDrawLine(display, window, gc, x1, y1, x2, y2); XFlush(display); } int main() { Display *display; Window window; XEvent event; GC gc; display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } int screen = DefaultScreen(display); unsigned long black = BlackPixel(display, screen); unsigned long white = WhitePixel(display, screen); window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, WIDTH, HEIGHT, 0, black, white); XSelectInput(display, window, ExposureMask | KeyPressMask); XMapWindow(display, window); gc = XCreateGC(display, window, 0, NULL); XSetForeground(display, gc, black); while (1) { XNextEvent(display, &event); if (event.type == Expose) { drawLine(display, window, gc, 50, 50, 450, 50); // 横线 drawLine(display, window, gc, 50, 50, 50, 250); // 竖线 drawLine(display, window, gc, 50, 250, 450, 250); // 横线 drawLine(display, window, gc, 450, 50, 450, 250); // 竖线 drawLine(display, window, gc, 100, 200, 200, 100); // 折线 XFlush(display); } if (event.type == KeyPress) break; } XFreeGC(display, gc); XDestroyWindow(display, window); XCloseDisplay(display); return 0; } ``` 这段代码使用Xlib库创建一个窗口,并在窗口中绘制一个简单的折线。你可以根据自己的需求修改代码,实现更复杂的折线功能。记得在编译时链接Xlib库,命令如下: ``` gcc your_code.c -o your_executable -lX11 ``` 编译后运行可执行文件即可在Linux系统上看到绘制的折线

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值