Search code examples
c++imagemagickphysfs

Magick++ not loading from blog


I am using Magick++ to load some images. Because I want to wrap PhysFS for all of my image loads, I needed to load an image by blob instead of file path.

This code:

    Magick::Image test("path/to/some.png");

Works without issue.

However once I do a blob I get an exception:

    PhysFS::ifstream img ("path/to/some.png");
    Magick::Blob blob( img.rdbuf(), img.length() );
    Magick::Image test(blob);

Exception thrown is:

terminating with uncaught exception of type Magick::ErrorMissingDelegate no decode delegate for this image format `' @ error/blob.c/BlobToImage/350

I have verified the blob is the same size as the file. So I am sure it is reading it into memory.

I tried using the standard library ifstream as well setting std::ios::binary but the problem remains.


Solution

  • Magick::Blob as a constructor needs a void*, in other words a memory location to read the data from. But you are providing pointer to a std::filebuf object and that won't work. You will have to read the file into memory. For example a char* and use that in the Blob constructor.