Page 1 of 1

Generic Error when saving an image

Posted: Tue Jun 05, 2018 8:01 am
by deatchlock
Hi,

i am having diffuculties with the following error: Unexpected exception occurred: System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at System.Drawing.Image.Save(String filename)
at TraversGUI.TraverseAlgorithm.GetAndStoreTextPictureAndOCRFromElement(Element e, String path) in c:\Users\xfsqa4\Documents\Ranorex\RanorexStudio Projects\TraversGUI\TraversGUI\TraverseAlgorithm.cs:line 243
at TraversGUI.TraverseAlgorithm.Traverse(String path) in c:\Users\xfsqa4\Documents\Ranorex\RanorexStudio Projects\TraversGUI\TraversGUI\TraverseAlgorithm.cs:line 111
at TraversGUI.Program.Main(String[] args) in c:\Users\xfsqa4\Documents\Ranorex\RanorexStudio Projects\TraversGUI\TraversGUI\Program.cs:line 40

I have been looking at these particular lines of code and I did debuging, my first assumption was that I have problem when saving the element by its name. (In the case of the date-time I had to do string formating which I did, but still error ocures).
The code where the error ocures:
Bitmap image = Imaging.CaptureImage(e);
string imagePathAndName = currentResultFolder+ path + "_" + e.GetAttributeValueText("Text").Replace(":","")+".bmp";
if(image.Size.Height>=500 || image.Size.Width>=500) {
if(image.Size.Height>image.Size.Width) {
image = resizeImage(image,new Size(((int)(450*image.Width/image.Height)),450));
}else{
image = resizeImage(image,new Size(450,((int)(450*image.Height/image.Width))));
}
}
image.Save(imagePathAndName);

Does anyone have Idea what could cause this error and how to solve it? Thanks

Re: Generic Error when saving an image

Posted: Tue Jun 05, 2018 8:06 am
by odklizec
Hi,

Have you tried to save the image with hardcoded filename and path? Simply, try to save it to c:\temp\test.bmp ;) If the error still occurs, then the problem is most probably somewhere else?

Re: Generic Error when saving an image

Posted: Tue Jun 05, 2018 8:18 am
by deatchlock
Hi,

thank you for the suggestion. You are right the error is somwhere else I have just tried your proposal. :S damn..

Re: Generic Error when saving an image

Posted: Tue Jun 05, 2018 8:23 am
by odklizec
Too bad. At least you now know the problem is somewhere else ;) Have you checked this post?...
https://stackoverflow.com/questions/155 ... g-an-image

Re: Generic Error when saving an image

Posted: Tue Jun 05, 2018 8:59 am
by deatchlock
Thanks for the link but I have discovered the reason why it didnĀ“t want to save. Since my traversing algorithm was taking text values from GUI elemnts including the date as well which has format :dd/mm/yyyy this forward slashes were casuing the error. So i have just added : e.GetAttributeValueText("Text").Replace("/","_").Replace(":","_")

Thank you for the help :)