该计划的整个目标是将8000张图片输出到屏幕上。这就是我在这方面取得的成就。
如果你可以帮我把图片而不是空白空间我应该很好,因为我不太熟悉xlib。
我想稍后更改屏幕上的图片。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
void draw(char *rgb_out, int w, int h)
{
for(int i=0; i<w*h*4; i++)
*rgb_out++ = rand();
}
XImage *create_ximage(Display *display, Visual *visual, int width, int height)
{
char *image32 = (char *)malloc(width * height * 4);
draw(image32, width, height);
return XCreateImage(display, visual, 24, ZPixmap, 0, image32, width, height, 32, 0);
}
int x11_err_handler(Display *pd, XErrorEvent *pxev)
{
char msg[4096] = { 0 };
XGetErrorText(pd, pxev -> error_code, msg, sizeof(msg));
printf("%s\n", msg);
return 0;
}
draw_graphics(Window win, GC gc, int window_width, int window_height)
{
int x, y;
unsigned int width, height;
height = window_height/2;
width = 3 * window_width/4;
x = window_width/2 - width/2; /* Center */
y = window_height/2 - height/2;
XDrawRectangle(display, win, gc, x, y, width, height);
}
int main (int argc, char *argv[])
{
Display *display;
Visual *visual;
int depth;
XSetWindowAttributes frame_attributes;
Window frame_window;
XFontStruct *fontinfo;
XGCValues gr_values;
GC graphical_context;
XKeyEvent event;
char hello_string[] = "Hello World";
int hello_string_length = strlen(hello_string);
int i = 0;
int t = 0;
int x = 15;
int y = 15;
display = XOpenDisplay(NULL);
visual = DefaultVisual(display, 0);
depth = DefaultDepth(display, 0);
frame_attributes.background_pixel = XWhitePixel(display, 0);
/* create the application window */
frame_window = XCreateWindow(display, XRootWindow(display, 0),
0, 0, 1200, 1200, 5, depth,
InputOutput, visual, CWBackPixel,
&frame_attributes);
XStoreName(display, frame_window, "Hello World Example");
XSelectInput(display, frame_window, ExposureMask | StructureNotifyMask);
fontinfo = XLoadQueryFont(display, "10x20");
gr_values.font = fontinfo->fid;
gr_values.foreground = XBlackPixel(display, 0);
gr_values.background = XWhitePixel(display, 0);
graphical_context = XCreateGC(display, frame_window,
GCFont+GCForeground+GCBackground, &gr_values);
XMapWindow(display, frame_window);
while ( 1 ) {
XNextEvent(display, (XEvent *)&event);
switch ( event.type ) {
case Expose:
{
while (i < 64){
i = 0;
while(i < 125)
{
XImage *ximage = create_ximage(display, visual, 125, 125);
XPutImage(display, frame_window, graphical_context, ximage, 0, 0, x, y, 9, 9);
XDestroyImage(ximage);
XFlush(display);
++i;
x = x + 9;
}
y = y + 9;
x = 9;
++t;
i = t;
}
usleep(2);
}
default:
break;
}
}
return(0);
}