Page 1 of 1

Blobs can't figure out image types?

Posted: 2010-02-02T07:45:07-07:00
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

Re: Blobs can't figure out image types?

Posted: 2010-02-02T07:48:46-07:00
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:.

Re: Blobs can't figure out image types?

Posted: 2010-02-02T08:05:05-07:00
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.

Re: Blobs can't figure out image types?

Posted: 2010-02-02T12:12:59-07:00
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.

Re: Blobs can't figure out image types?

Posted: 2010-02-02T17:04:46-07:00
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?

Re: Blobs can't figure out image types?

Posted: 2010-02-02T17:10:05-07:00
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.

Re: Blobs can't figure out image types?

Posted: 2010-02-03T03:12:55-07:00
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.