简体   繁体   中英

Examples of Magick++ api and ping (not networking ping)

I'm trying to use the Magick++ API (part of ImageMagick) for c++ and I've been looking around a while now and haven't seen that much documentation or examples on google. There's a lot of good documentation about it, but I can't find anything on how to use the ping() (not networking ping) function to return the size information of an image inside a c++ program. I've tried to make a blob object and use it like I've seen in the error.

I've seen a lot of the same general manual like:

http://web.mit.edu/graphics/share/ImageMagick/www/Magick++/Image.html#Image%20Attributes which is the same as http://www.imagemagick.org/Magick++/Image.html

I was looking at ping under "Image Manipulation Methods" and saw that it took a const Blob &blob_ as input. I tried doing the following, though I'm not really sure what I'm doing with ping() . I've got a lot of other stuff working, just can't figure this out.

#include <Magick++.h> 
#include <iostream> 
using namespace std; 
using namespace Magick; 
int main(int argc,char **argv) 
{ 
        InitializeMagick(*argv);

        Image master("horse.jpg"); 
        Image second = master; 

        // tried creating a blob (Binary Large OBject) per the error
        Blob blob; 
        master.write ( &blob);  

        cout << blob.ping(&blob) << endl; 
        // also tried
        // cout << master.ping() << endl;
        // cout << master.ping( &blob) << endl;

        return 0
} 

I can't even find much in the way of examples for Magick++ stuff or ping.

test3.cpp:15:26: note: candidates are:
In file included from /usr/include/ImageMagick/Magick++.h:10:0,
                 from test3.cpp:1:
/usr/include/ImageMagick/Magick++/Image.h:501:21: note: void Magick::Image::ping(const string&)
     void            ping ( const std::string &imageSpec_ );
                     ^
/usr/include/ImageMagick/Magick++/Image.h:501:21: note:   candidate expects 1 argument, 0 provided
/usr/include/ImageMagick/Magick++/Image.h:507:21: note: void Magick::Image::ping(const Magick::Blob&)
     void            ping ( const Blob &blob_ );
                     ^
/usr/include/ImageMagick/Magick++/Image.h:507:21: note:   candidate expects 1 argument, 0 provided

So I guess ping returns void which it didn't say in the manual. I'm not even sure how I'd get values from it. Should I just take a look at the source code? Does anyone know where I could find more reading on this? Or is anyone familiar with Magick++. I'm sorry for being so clueless but google just isn't turning up much in the way of results for me about this.

Any help would be much appreciated!

The return type of ping is 'void' because it almost does the same as read . The ping method reads all the meta-data from the image but stops processing the image as soon as the part that contains the 'pixel data' is reached. You cannot read the 'pixel data' but you can get the columns() and rows() after the image has been 'pinged'. This information is also available in the documentation of Magick++ that can be found here: http://www.imagemagick.org/Magick++/Image.html .

Below is an example of how you can use the ping method:

#include <Magick++.h> 
#include <iostream> 
using namespace std; 
using namespace Magick; 
int main(int argc,char **argv) 
{ 
  InitializeMagick(*argv);

  Image master; 
  master.ping("horse.jpg");
  cout << master.columns() << "x" << master.rows() << endl; 

  return 0;
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM