ico decode from blob failed

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
carbon0404
Posts: 17
Joined: 2012-04-11T05:11:30-07:00
Authentication code: 8675308

ico decode from blob failed

Post 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?
carbon0404
Posts: 17
Joined: 2012-04-11T05:11:30-07:00
Authentication code: 8675308

Re: ico decode from blob failed

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: ico decode from blob failed

Post 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.
carbon0404
Posts: 17
Joined: 2012-04-11T05:11:30-07:00
Authentication code: 8675308

Re: ico decode from blob failed

Post 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!
Post Reply