Blobs can't figure out image types?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
Seriema

Blobs can't figure out image types?

Post by Seriema »

Hello,

I'm writing a shell extension where I get a file stream and need to create a thumbnail. I thought Blobs would be perfect for this but it seems that not all image formats are detected? For example, if I pass a PNG it works, but if I pass a TGA it doesn't.

The code is really straightforward:

Code: Select all

Magick::Image foo(Magick::Blob(data, dataLength));
foo.resize(Magick::Geometry(thumbnailSize, thumbnailSize));
return ImageToHBITMAP(foo.image());
Have I misunderstood something? How can I make it work for all supported file types? I've tried the other ctor that takes a Blob, although I do know the file extension/type I do not know the geometry/size of the image.

Thank you,
JP
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Blobs can't figure out image types?

Post by magick »

Some formats do not have magic numbers to help identify the image format. For those, set the image filename and ImageMagick will use it as hint for the image format. For example, a filename of image.tga tells ImageMagick the blob is in the TARGA format. Or you can set the image magick as TGA:.
Seriema

Re: Blobs can't figure out image types?

Post by Seriema »

I have tried that method but couldn't get it to work. It throws an exception. I did it like this:

Code: Select all

Magick::Image image;
image.magick(extension);
image.read(Magick::Blob(data, dataLength));
return ImageToHBitmap(image.image());
Is there a different way that works? I don't know the geometry size so I can't set that.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Blobs can't figure out image types?

Post by magick »

Use this method:
  • Magick::Image::Image ( const Blob &blob_,
    const Geometry &size_,
    const std::string &magick_ )
Size is ignored if the image format is not raw.
Seriema

Re: Blobs can't figure out image types?

Post by Seriema »

That hasn't worked for me so far. If I try that on a TGA image:

Magick::Image foo(Magick::Blob(data, dataLength), Magick::Geometry(), extension);
gives me a Image that returns a invalid HBITMAP.

Magick::Image foo(Magick::Blob(data, dataLength), Magick::Geometry(thumbnailSize, thumbnailSize), extension);
gives me a black square.

How can I make it ignore the Geometry parameter?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Blobs can't figure out image types?

Post by magick »

Post a short program we can download and compile to reproduce the problem and include an example Targa image. We need to reproduce the problem before we can offer any additional advice.
Seriema

Re: Blobs can't figure out image types?

Post by Seriema »

I found my error while writing a small sample. I was giving ".tga" instead of "tga". "filename.tga" didn't work either. "tga" is working perfectly! Thank you very much for the help.
Post Reply