スクリーンキャスティングで使用するために、画面のイメージをキャプチャしようとしています。したがって、私は高速なソリューションが必要であり、importやxwdなどのシェルプログラムに依存することはできません。xlibでスクリーンショットを正しく撮るにはどうすればよいですか?
これは私がこれまでに書いたコードですが、失敗し、奇妙な色の複数の画像の破片が一緒に投げ込まれているように見える迷惑な画像が表示されます。
http://s9.postimage.org/dqnkgkwr1/blah.png
私が間違っているのかについての任意のアイデア? (
printf("%ld %ld %u %u %u\n",x,y,pic.offset(x,y,0),pic.offset(x,y,1),pic.offset(x,y,2));
この利回り:
#include <X11/Xlib.h>
#include <X11/X.h>
#include <cstdio>
#include <CImg.h>
using namespace cimg_library;
int main()
{
Display *display = XOpenDisplay(NULL);
Window root = DefaultRootWindow(display);
XWindowAttributes gwa;
XGetWindowAttributes(display, root, &gwa);
int width = gwa.width;
int height = gwa.height;
XImage *image = XGetImage(display,root, 0,0 , width,height,AllPlanes, ZPixmap);
unsigned char *array = new unsigned char[width * height * 3];
unsigned long red_mask = image->red_mask;
unsigned long green_mask = image->green_mask;
unsigned long blue_mask = image->blue_mask;
for (int x = 0; x < width; x++)
for (int y = 0; y < height ; y++)
{
unsigned long pixel = XGetPixel(image,x,y);
unsigned char blue = pixel & blue_mask;
unsigned char green = (pixel & green_mask) >> 8;
unsigned char red = (pixel & red_mask) >> 16;
array[(x + width * y) * 3] = red;
array[(x + width * y) * 3+1] = green;
array[(x + width * y) * 3+2] = blue;
}
CImg<unsigned char> pic(array,width,height,1,3);
pic.save_png("blah.png");
printf("%ld %ld %ld\n",red_mask>> 16, green_mask>>8, blue_mask);
return 0;
}
こんにちは@lalalandあなたの最終的なコードを共有してください、これはマルチモニタをサポートしていますか? – Noitidart
@Noitidartはい、私は複数のモニターをサポートしました。私はhttps://github.com/Lalaland/ScreenCap/blob/master/src/screenCapturerImpl.cppが正しいファイルかもしれないと思う。しかし、何年もコードに触れていない。コードは記述が不十分ですが、使用したい場合はそこにBSDライセンスを送ります。 – Lalaland
大変ありがとうございました。あなたの問題のページに投稿して、それがマルチモニタでどのように動作するのか理解できる時間があれば、どうかしてください。 – Noitidart