Problem reading a TIFF file

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
peter01242
Posts: 17
Joined: 2016-06-22T11:32:57-07:00
Authentication code: 1151

Problem reading a TIFF file

Post by peter01242 » 2016-06-29T16:14:02-07:00

I am using the following code to read a TIFF file, resample it at 300 dpi, and save it as an 8-bit deep PNG.
I have managed to get this working via command line arguments (I used mogrify not convert).
The code below throws an exception during the read(). The exception is:
Thumbnail Generation failed: XiThumbnail.exe: unable to open image '(÷.c»': Invalid argument @ error/blob.c/OpenBlob/2695

Code: Select all

		std::string SrcPath = "T:\Catfish\trunk\catfish\Tools\XiThumbnail\x64\Debug\a(C).TIF";

		TheImage.read(SrcPath);								// Load the image.
		TheImage.magick(ThumbnailFormat.GetBuffer(0));		// Set the destination format.

		Magick::Point Sample((double)nThumbnailResolutionDPI, (double)nThumbnailResolutionDPI);
		TheImage.resample(Sample);							// Resample to the required resolution.
		TheImage.depth(8);									// Make it an 8-bit thumbnail.

		CString DestPath = _T("");
		if(TargetFolder.IsEmpty())
			TargetFolder = RemoveExtension(SrcFile) + _T(".") + ThumbnailFormat;
		else
			JoinPath(TargetFolder, RemoveExtension(GetLeafname(SrcFile))) + _T(".") + ThumbnailFormat;

		dst = TargetFolder.GetBuffer(0);
		TheImage.write(dst);								// Save it to disk in the target location.
Any suggestions gratefully received.
Thanks,

Peter Young

snibgo
Posts: 9383
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem reading a TIFF file

Post by snibgo » 2016-06-29T16:55:44-07:00

In C, backslash \ in a string has a special meaning. As you don't want that special meaning, you need to escape it.
snibgo's IM pages: im.snibgo.com

peter01242
Posts: 17
Joined: 2016-06-22T11:32:57-07:00
Authentication code: 1151

Re: Problem reading a TIFF file

Post by peter01242 » 2016-06-29T17:32:27-07:00

Even if I use \\ I get the same problem, an exception:
"T:\\catfish\\trunk\\catfish\\tools\\XiThumbnail\\x64\\debug\\a(C).tif"
The only difference being that the exception now says:
unable to open image '¸䀀q½¡': No such file or directory @ error/blob.c/OpenBlob/2695

The file definitely exists in the folder as this screenshot shows:
[img]
https://www.dropbox.com/s/fcn990kspf3kp ... p.PNG?dl=0
[/img]

The messy stuff after the 'unable to open image' text is generated by M++ so I can only assume I am passing the string in incorrectly.
I have removed everything else that I can to try and simplify this example.

Code: Select all

	std::string src = "T:\\catfish\\trunk\\catfish\\tools\\XiThumbnail\\x64\\debug\\a(C).tif";
	try
	{
		Magick::Image TheImage(src);								// Load the image.
	}
	catch (Magick::Exception &error_ )
	{
		LOG("Thumbnail Generation failed: %s\r\n", error_.what());
		return;
	}
The InitializeMagick() method requires the first argv value (application path). What does it use this for?
I have IM installed but do not have the associated DLLs next to the app.
Additionally, is IM Unicode or MBCS?

Thanks,

Pete Young

snibgo
Posts: 9383
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem reading a TIFF file

Post by snibgo » 2016-06-29T17:47:49-07:00

As far as I know, IM assumes text is UTF-8. It doesn't do much character processing.

I have no idea what M++ is.

I suggest you show a complete but minimal program.

I also suggest, if you haven't already, that you write a few "Hello World" programs, before the complications of IM. It only takes a few hours, but it gets you beyond the hurdles of the language and your development environment.
snibgo's IM pages: im.snibgo.com

peter01242
Posts: 17
Joined: 2016-06-22T11:32:57-07:00
Authentication code: 1151

Re: Problem reading a TIFF file

Post by peter01242 » 2016-06-29T19:05:50-07:00

FYI, I have the ImageMagick-7.0.2-0-Q8-x64-dll.exe and ImageMagick-7.0.2-0-Q8-x86-dll.exe installations installed.
I am building under VS2013 (12.0.40629.00 Update 5).

I am a relatively experienced programmer and have been programming C and C++ for several years, so I am probably beyond the 'Hello World' stage.

Here is my minimal code

Code: Select all

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	std::string w = *argv;
	printf("Initializing Magick++ with: %s\r\n", w.c_str());
	try {
		Magick::InitializeMagick(w.c_str());
	}
	catch(Magick::ErrorBlob e) {
		printf("Error initializing Magick++: %s\r\n", e.what());
	}

	std::string s = "T:\\catfish\\trunk\\catfish\\tools\\XiThumbnail\\a.tif";
	try {
		Magick::Image Im(s);
	}
	catch(Magick::Exception e) {
		printf("Error reading '%s': %s\r\n", s.c_str(), e.what());
	}
	return 0;
}
This fails in the same way with both 32 and 64 bit builds.

peter01242
Posts: 17
Joined: 2016-06-22T11:32:57-07:00
Authentication code: 1151

Re: Problem reading a TIFF file

Post by peter01242 » 2016-06-30T17:04:08-07:00

It turns out that, for some reason, you cannot debug properly in Debug mode under VS2013 - Magick++ gets upset.
I have noticed some incompatibilities between Debug and Release code that did not, AFAICR, exist under previous versions of VS.

Am now generating thumbnails and moving on the next stage.
Thanks for all the help - it made my life a lot easier.

Pete Y

rajeevraina
Posts: 6
Joined: 2017-03-02T04:42:11-07:00
Authentication code: 1151

Re: Problem reading a TIFF file

Post by rajeevraina » 2017-03-03T02:15:59-07:00

Hi Peter

I am facing the same problem (VS2008). I get the error message "Unable to open image ']->@' : invalid argument @ error/blob.c/OpenBlob/3094"

Do you get any idea about the possible probem based upon this message.

Please help

Post Reply