问题
I have a vector containing RGBA (actualy I don't care about the alpha channel) value from a picture, I want to draw this picture with xlib. So I have to use an XImage and to got one I need to use XCreateImage.
XCreateImage requires "char *data" so first I need to convert my vector. I don't know if what I'm doing is efficient, but that works :
vector<unsigned char> picture;
cunsigned char *unsigneddata = &picture[0];
char *data;
data = (char*)unsigneddata;
so now I can use "data" to draw my picture,
XImage *ximage = XCreateImage(display, visual /*errata : not window*/, 24, ZPixmap, 0, data, width, height, 32, 0);
XPutImage(dpy, *_w,gc,ximage,0,0,0,0,width,height);
my picture at screen has the red and the blue channels inverted. I don't know if I mess something or if it's correct and if I have to swap the channels. If I have to swap, there is another way than just doing a loop over the array to swap them ?
回答1:
you know what? I'm tired of dat shit! I just swap the values...
// invert red and blue, xlib ams dumb, it using BGR instead of RGB...
unsigned char red, blue;
int i;
for(i=0;i<image.size();i+=4){
red = image[i+2];
blue = image[i];
image[i] = red;
image[i+2] = blue;
}
thank you for your comments n.m.
来源:https://stackoverflow.com/questions/17017432/linux-c-ximage-rgb-bgr