[Solved] ‘CharPixel’ was not declared in this scope

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
danieru
Posts: 10
Joined: 2014-06-13T11:48:15-07:00
Authentication code: 6789

[Solved] ‘CharPixel’ was not declared in this scope

Post by danieru »

When trying to obtain the RGB data with:

Code: Select all

image.write(0, 0, width, height, "RGB", CharPixel, data);
I get an error while compiling:

Code: Select all

main.cpp: In constructor ‘MyArea::MyArea()’:
main.cpp:51:44: error: ‘CharPixel’ was not declared in this scope
    image.write(0, 0, width, height, "RGB", CharPixel, data);
                                            ^
main.cpp:51:44: note: suggested alternatives:
In file included from /usr/include/ImageMagick/magick/pixel.h:26:0,
                 from /usr/include/ImageMagick/magick/color.h:25,
                 from /usr/include/ImageMagick/magick/image.h:25,
                 from /usr/include/ImageMagick/magick/draw.h:26,
                 from /usr/include/ImageMagick/magick/annotate.h:25,
                 from /usr/include/ImageMagick/magick/MagickCore.h:66,
                 from /usr/include/ImageMagick/Magick++/Include.h:43,
                 from /usr/include/ImageMagick/Magick++.h:9,
                 from main.cpp:2:
/usr/include/ImageMagick/magick/constitute.h:28:3: note:   ‘CharPixel’
   CharPixel,
   ^
/usr/include/ImageMagick/magick/constitute.h:28:3: note:   ‘CharPixel’
This is pretty weird to me because the documentation says "Pixel storage type (CharPixel, ShortPixel, IntegerPixel, FloatPixel, or DoublePixel)"

Here's the full code:

Code: Select all

#include <Magick++.h>
#include <gtkmm.h>
#include <iostream>

using namespace std;

class MyArea : public Gtk::DrawingArea
{
public:
  MyArea();
  virtual ~MyArea();

protected:
  //Override default signal handler:
  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);

  Glib::RefPtr<Gdk::Pixbuf> m_image;
};

int main(int argc, char** argv)
{
  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

  Gtk::Window win;
  win.set_title("magick++ && gtkmm");
  win.set_default_size(445, 287);

  MyArea area;
  win.add(area);
  area.show();

  return app->run(win);
}

MyArea::MyArea()
{
  try
  {

   Magick::Image image( "fractal_image.png" );
   guchar data;
   int width;
   int height;
   width = image.columns();
   height = image.rows();

   image.write(0, 0, width, height, "RGB", CharPixel, data);  //  Strange error in the sixth argument  //

  }
  catch(const Glib::FileError& ex)
  {
    std::cerr << "FileError: " << ex.what() << std::endl;
  }
  catch(const Gdk::PixbufError& ex)
  {
    std::cerr << "PixbufError: " << ex.what() << std::endl;
  }

}

MyArea::~MyArea()
{
}

bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
   if (!m_image)
      return false;

   Gtk::Allocation allocation = get_allocation();
   const int width = allocation.get_width();
   const int height = allocation.get_height();

   // Draw the image in the middle of the drawing area, or (if the image is
   // larger than the drawing area) draw the middle part of the image.
   Gdk::Cairo::set_source_pixbuf(cr, m_image,
    (width - m_image->get_width())/2, (height - m_image->get_height())/2);

   cr->paint();

   return true;
}

Code: Select all

g++ `Magick++-config --cxxflags --cppflags` main.cpp -o main `pkg-config gtkmm-3.0 --cflags --libs` `Magick++-config --ldflags --libs`
and the versions:
library: ImageMagick 6.7.7-10
library: gtkmm 3.0
compiler: g++ 4.8.2
OS: Ubuntu 14.04 (amd64)
I would greatly appreciate any help.
danieru
Posts: 10
Joined: 2014-06-13T11:48:15-07:00
Authentication code: 6789

Re: [Solved] ‘CharPixel’ was not declared in this scope

Post by danieru »

Solved: I just forgot the magic word "Magick::" :oops:
Post Reply