note that i still haven't resolved the last issue, but am continuing development in visual studio for now.
I'm writing a program that does a number of IM operations, and am using a small set of pretty much random images as a test set. I'm also using a wide variety of settings, and in one of my test settings, and on one of my test files, the (earlier) crop operation results in a purely white background image (the source is a letter flashcard, but the letter gets cropped out, leaving the blank white space). When trimming this, the program throws a fatal error and crashes.
1) is this a bug that should be fixed? And if so, if someone could point me to the appropriate place to report it, I'd be happy to. I can of course provide the file, but any file which would be trimmed to 0 pixels produces the crash afaik.
2) what is the best workaround? the logical solution would be to check boundingBox() and if it's ==0, then skip trimming -- but unfortunately, calling boundingBox() on the offending image causes the same crash. I *think* there's a way that I can essentially manually calculate the trim results, by taking the min and max colors, or max color distance, or something like that, but A) is that the best solution, and B) how would I go about doing so?
program crash when trimming a solid color image
Re: program crash when trimming a solid color image
A pure white image should thrown an exception. Verify you are catching the exception. Otherwise post a URL to a small Magick++ program that can we can download to reproduce the problem plus the image you're using.
Re: program crash when trimming a solid color image
this was indeed the problem -- me not catching the exception. much thanks for the quick response.
for anyone else who has a similar problem, here is some simple code to handle it for you.
*this code will continue with an empty image (0 pixels)*
if you want to try to trim, and retry trimming with a lower fuzz value until it succeeds (untested, not useful for me),
obviously, increments of more than one for decrease might be in order, given that fuzz can be a high number.
for anyone else who has a similar problem, here is some simple code to handle it for you.
*this code will continue with an empty image (0 pixels)*
Code: Select all
try{yourimage.trim();}
catch(...){}
*this code will skip trimming the image*
try{workingfiles.back().boundingBox();}
catch(...){skip=1;}
if(skip==0)workingfiles.back().trim();
else skip=0;
Code: Select all
int decrease=0;
while(1){
yourimage.colorFuzz(initialfuzz-decrease);
try{yourimage.trim();}
catch(...){
decrease++;
if(initialfuzz-decrease>-1)continue;
}
break;
}