2015-02-23 22:21 GMT+01:00 Markus Kolb <markus.kolb+gt...@tower-net.de>:

> Am 2015-02-23 21:40, schrieb Glus Xof:
>
>> Hi guys,
>>
>> Before anything, I admit that probably my question is not an specifically
>> Gtkmm question... but nevertheless I think you may know how Gdk::Pixbuf is
>> done...
>>
>> Having the following,
>>
>> Glib::RefPtr<Gdk::Pixbuf> ref_orig = Gdk::Pixbuf::create_from_file
>> ("./file.png");
>>
>> I'm trying to temporary store (because I need so) the image data into a
>> std::string object. It seems that get_pixels() could solve the problem,
>> getting a pointer of type guint8.
>>
>
> Seems that gdkmm is not up-to-date here.
> gdk uses a guchar*. But this shouldn't be a problem.
>


>  So, I wrote as follows,
>>
>> std::string image_pixels (reinterpret_cast<const char
>> *>(ref_orig->get_pixels()), ref_orig->get_rowstride());
>>
>
> I think this does not what you expect.
>
> https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-
> The-GdkPixbuf-Structure.html#gdk-pixbuf-get-rowstride
>
> See also the part below the description headline.
>
> Maybe you should use gsize Gdk::Pixbuf::get_byte_length()
> because https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-
> The-GdkPixbuf-Structure.html#gdk-pixbuf-get-pixels-with-length is missing.
>
> I hope it will help you.
>
> But think about the std::string. Big ? ;-)
>
>
According to Yann & Markus' comments, I remake my code as follows,

Glib::RefPtr<Gdk::Pixbuf> ref_orig = Gdk::Pixbuf::create_from_file
("./file.png");

// Glib::ustring::c_str() or data() allows me to get an std::string
object...

Glib::ustring image_pixels (
      reinterpret_cast<const char *>(ref_orig->get_pixels()),
      ref_orig->get_byte_length());

Glib::RefPtr<Gdk::Pixbuf> ref_dest =
      Gdk::Pixbuf::create_from_data (
         reinterpret_cast<const guint8*>(image_pixels.data()),
Gdk::COLORSPACE_RGB,
         ref_orig->get_has_alpha(), ref_orig->get_bits_per_sample(),
         ref_orig->get_width(), ref_orig->get_height(),
ref_orig->get_rowstride());

But, at runtime I get a lenght error exception,

terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_S_create

Could help ?

Glus






> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtkmm-list
>
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to