Re: How to store Gdk::Pixbuf pixels into std::string objects



(Oops, sent from wrong address first time)

On 24/02/15 12:28, Glus Xof wrote:

I need your help...

I insist that maybe it's not an specifically Gtkmm question... but you
may know better how it's done, the library...

It's not even related to the library, really. The issue here is a basic
C++ issue.


Gdk::Pixbuf::get_pixels()... returns a guint8 (const unsigned char)
pointer. So,

1) Which is the best way to build an std::string object containing the
data of the buffer (the pixels)... ?

The best way, as you've been told, is to "Not do that". It's the Wrong
Thing To Do.

<snip>

Why std::vector(s) should be used, here ?

Because a std::vector<guint8> is the correct container for binary data.
A std::string is a container for a string, which is text, and which can
be expected to obey rules for text, such as not containing null
characters because they terminate C-strings.

What benefit do you expect to obtain from using std::string? It can't be
any of the special methods for handling text, because you're not
populating it with text. And that only leaves base methods common to all
std:: container classes.

So use std::vector


==

Once an std::string object created... and from this object...

2) Which is the best way to convert it back to guint8 (const unsigned
char) pointer, in order to pass it as first argument to
Gdk::Pixbuf::create_from_data() ?

One of the nice things about a std::vector<x> is that it provides a
method to directly expose the underlying C-style array of x - in your
case the guint8* that you want.



I'd like to know how to realize these two steps... even if building
std::string objects sounds a little silly or strange... I wonder... is
it possible ?

It sounds silly, strange, ill-thought-out and inappropriate. Why do you
have this fixation with doing things the wrong way when the right way is
easier?

HTH
Rob





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]