Loading Image from a project in user code
-
- Posts: 3
- Joined: Tue Aug 25, 2015 12:35 pm
Loading Image from a project in user code
I have added an existing item (png) into my project. I would like to know the correct way to use Imaging.Load() to be able to do validations based on this.
Re: Loading Image from a project in user code
Hi and welcome here,
If you want to compare your png file against a repo item, you can use code like this:
Or like this, if you want to override Ranorex defaut FindOptions...
You can find some more examples here:
http://www.ranorex.com/support/user-gui ... html#c3326
or by searching this forum
If you want to compare your png file against a repo item, you can use code like this:
Code: Select all
image = Imaging.Load ("c:\path\to\file.png");
Validate.ContainsImage(RepoItemInfo, image, Imaging.FindOptions.Default, "Image validation", true);
Code: Select all
Imaging.FindOptions MyFindOptions = new Imaging.FindOptions(0.95);
Validate.ContainsImage(RepoItemInfo, image, MyFindOptions, "Image validation", true);
http://www.ranorex.com/support/user-gui ... html#c3326
or by searching this forum

Last edited by odklizec on Tue Feb 07, 2017 9:00 am, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 3
- Joined: Tue Aug 25, 2015 12:35 pm
Re: Loading Image from a project in user code
Thanks for your response,
For now I will be making do with using the default relative ranorex working directory path (bin\debug) and then getting it's grandparent, which is where Ranorex copied the files when they were imported. It works, but I suspect it will not once it is compiled.
This is because I cannot guarantee where the files will be on various test pcs. I need a way to perhaps reference these assets in a relative fashion, as if they were in the repo.
For now I will be making do with using the default relative ranorex working directory path (bin\debug) and then getting it's grandparent, which is where Ranorex copied the files when they were imported. It works, but I suspect it will not once it is compiled.
This is because I cannot guarantee where the files will be on various test pcs. I need a way to perhaps reference these assets in a relative fashion, as if they were in the repo.
Re: App get crashed while tap on element in iOS Instrumented app
If you already added the image file to your project, then you can now set it to always copy to output directory, which means the file will be copied (during build) to bin/debug or bin/release folder. In Projects view select the file and then in Properties set Copy to output dir. to Always.
Then you can use this code to get the path of debug/release dir...
string path = Ranorex.Core.Testing.TestSuite.WorkingDirectory;Hope this helps?
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 3
- Joined: Tue Aug 25, 2015 12:35 pm
Re: Loading Image from a project in user code
Thank you so much, I think this will do it.
EDIT: Working, thank you.
EDIT: Working, thank you.
Re: Loading Image from a project in user code
Hi,
I came across this thread and have found out that this was what I needed for my current test case. However, I am stuck after the code for getting the path of the debug/release dir. How do I go through the path of where my Image is? Currently my image is stored on a folder called Images and it has been copied on the release dir since I specified the copy to output directory to always. I tried something like image = Imaging.Load ("c:\path\Images\specific_image.png"); yet I have encountered an error on unrecognized escape sequence. Am I doing it wrong? It's my first time actually trying the image validation and I'm still exploring..Thank you very much. Currently this is my code:
string path = Ranorex.Core.Testing.TestSuite.WorkingDirectory;
image = Imaging.Load ("c:\path\Images\specific_image.png");
Imaging.FindOptions MyFindOptions = new Imaging.FindOptions(0.95);
Validate.ContainsImage(repo.App.Text1478Info,(System.Drawing.Bitmap) image, MyFindOptions, "Image validation", true);
Please advise..
Thank you in advance
I came across this thread and have found out that this was what I needed for my current test case. However, I am stuck after the code for getting the path of the debug/release dir. How do I go through the path of where my Image is? Currently my image is stored on a folder called Images and it has been copied on the release dir since I specified the copy to output directory to always. I tried something like image = Imaging.Load ("c:\path\Images\specific_image.png"); yet I have encountered an error on unrecognized escape sequence. Am I doing it wrong? It's my first time actually trying the image validation and I'm still exploring..Thank you very much. Currently this is my code:
string path = Ranorex.Core.Testing.TestSuite.WorkingDirectory;
image = Imaging.Load ("c:\path\Images\specific_image.png");
Imaging.FindOptions MyFindOptions = new Imaging.FindOptions(0.95);
Validate.ContainsImage(repo.App.Text1478Info,(System.Drawing.Bitmap) image, MyFindOptions, "Image validation", true);
Please advise..
Thank you in advance
Re: Loading Image from a project in user code
You must use double backslash...
Or @ character in front of the path:
Second solution is better, because you will most probably not use hardcoded path but variable? So it's better to go this way.
Code: Select all
image = Imaging.Load("c:\\path\\Images\\specific_image.png");
Code: Select all
image = Imaging.Load (@"c:\path\Images\specific_image.png");
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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