Generic Error when saving an image

Class library usage, coding and language questions.
deatchlock
Posts: 27
Joined: Mon Mar 19, 2018 10:02 am

Generic Error when saving an image

Post by deatchlock » Tue Jun 05, 2018 8:01 am

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Generic Error when saving an image

Post by odklizec » Tue Jun 05, 2018 8:06 am

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?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

deatchlock
Posts: 27
Joined: Mon Mar 19, 2018 10:02 am

Re: Generic Error when saving an image

Post by deatchlock » Tue Jun 05, 2018 8:18 am

Hi,

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Generic Error when saving an image

Post by odklizec » Tue Jun 05, 2018 8:23 am

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
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

deatchlock
Posts: 27
Joined: Mon Mar 19, 2018 10:02 am

Re: Generic Error when saving an image

Post by deatchlock » Tue Jun 05, 2018 8:59 am

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 :)