简体   繁体   English

Linux C ++ XImage RGB <-> BGR?

[英]linux C++ XImage RGB <-> BGR?

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. 我有一个从图片包含RGBA(实际上我不在乎alpha通道)值的向量,我想用xlib绘制此图片。 So I have to use an XImage and to got one I need to use XCreateImage . 因此,我必须使用XImage并使用XCreateImage来获得一个。

XCreateImage requires "char *data" so first I need to convert my vector. XCreateImage需要“ char * data”,因此首先我需要转换向量。 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 ? 如果必须交换,除了在数组上循环以交换它们之外,还有另一种方法吗?

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 nm 谢谢你的评论nm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM