0

I am trying to get pixel rgb values from previously captured screen area. After saving gdk_pixbuf_get_pixels() data to a file I just get weird signs insted of rgb pixel value. I have no idea what is it and how to read it. In python I was getting straight 3D array with rgb value but in c++ I am stuck at this.

Pixels saves as:

>lł>lł>lł>lł>lł>lł>lł>lł>lł>lł>lł>lłdŠŔŁ¸ÖľĚßŮŕčçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíÖŢčłĆÝ’­ŇAtąS¬S¬S¬S¬S«S«S«Cuş’­ÓłĆÝÖŢčçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęíçęí

And my code is:

        GdkPixbuf *pxbuf;

        GdkWindow *wind = gdk_get_default_root_window();
        pxbuf = gdk_pixbuf_get_from_window(wind, 0, 0, 500, 500);

        guchar *px = gdk_pixbuf_get_pixels(pxbuf);

        ofstream myfile;
        myfile.open("px.txt");
        myfile << px;
        myfile.close();
Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
  • Have a look into doc. [`gdk_pixbuf_get_pixels ()`](https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-The-GdkPixbuf-Structure.html#gdk-pixbuf-get-pixels): _A pointer to the pixbuf's pixel data. Please see the section on [image data](https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-The-GdkPixbuf-Structure.html#image-data) for information about how the pixel data is stored in memory._ (The original link in doc. is broken but I found it.) What you see on Console doesn't make much sense: These are your pixelbytes "spelled" as characters of current locale. – Scheff's Cat Jul 05 '19 at 05:59
  • `myfile << px` You are trying to *format* an array of characters a.k.a. "C style string". Except that it's not necessarily null terminated, or may contain null chars in places you don't expect. Don't use formatted output to write binary data. – n. m. could be an AI Jul 05 '19 at 06:26

0 Answers0