0

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!

4

1 回答 1

0

ping的返回类型是 'void' 因为它几乎和read一样。ping方法从图像中读取所有元数据,但一旦到达包含“像素数据”的部分,就会停止处理图像。您无法读取“像素数据”,但您可以在“ping”图像后获取columns()rows() 。此信息也可在 Magick++ 的文档中找到,可在此处找到:http ://www.imagemagick.org/Magick++/Image.html 。

以下是如何使用ping方法的示例:

#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;
} 
于 2015-03-09T09:45:58.580 回答