Page 1 of 1

ico decode from blob failed

Posted: 2012-10-23T20:15:57-07:00
by carbon0404
I use the ImageMagick-6.7.9-10 installed from source code on linux,and then write a very simple code to test IM API for for format conversion.like following:

Code: Select all

    Image image(argv[1]); 
    image.magick( argv[2] ); // Set JPEG output format
    cout<<"File Name after magick:"<<image.fileName()<<endl;
    image.write(argv[3]);   
    Geometry origgeo = image.size();
    int width = origgeo.height();
    int height = origgeo.width();
    cout<<"w:"<<width<<",h:"<<height<<endl;
run the program like this:"./zhuan input format output";
when i run it with Image,it works well.
then i change the way,code like this:

Code: Select all

string strPic = TC_File::load2str(argv[1]);
char* data = strPic.c_str();
size_t len = strPic.length();
m_blob.update(data, len);
//m_blob.updateNoCopy(data,len);
m_image.read(m_blob);
m_image.magick(argv[2])
image.write(argv[3]);   
    Geometry origgeo = image.size();
    int width = origgeo.height();
    int height = origgeo.width();
    cout<<"w:"<<width<<",h:"<<height<<endl;
the load2str function just read the file content into a string in memory.when i run the second program,it prints ":Magick: no decode delegate for this image format `' @ error/blob.c/BlobToImage/361, url:favicon.ico"

I can not figure out why it does not work.At a glance,there are really some difference in getting the original image between use the Image constructor and read from blob.
In my opinion,no matter read from a disk file,or read from a in-memory blob,the same input file should be process the same.Is that right?

Re: ico decode from blob failed

Posted: 2012-10-26T01:56:56-07:00
by carbon0404
I noticed that the difference between these two way lie in that Image constructor will call the 'void Magick::Image::read ( const std::string &imageSpec_ )'in Image.cpp while the other will call the 'void Magick::Image::read ( const Blob &blob_ )',is this the reason?some pic format can only read data from file stream? can anyone give me some inclues?

Re: ico decode from blob failed

Posted: 2012-10-26T04:08:38-07:00
by magick
The ICO format does not have a magic string to help identify it like JPEG or PNG does. Instead you must hint to ImageMagick the format the blob is in. Use magick("ICO") before you read the blob.

Re: ico decode from blob failed

Posted: 2012-10-29T00:51:45-07:00
by carbon0404
magick wrote:The ICO format does not have a magic string to help identify it like JPEG or PNG does. Instead you must hint to ImageMagick the format the blob is in. Use magick("ICO") before you read the blob.
thank you so much.With your help,I have solved it successfully!