Can I check for pixel's color in some area for validation

Ask general questions here.
MGeorgiev
Posts: 2
Joined: Tue Mar 29, 2016 4:51 pm

Can I check for pixel's color in some area for validation

Post by MGeorgiev » Tue Mar 29, 2016 4:56 pm

I'm trying to do validation and check for some color ( red). If there is red pixel into that screenshot to fail the validation. Is there any chance to do that in Ranorex ?

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

Re: Can I check for pixel's color in some area for validation

Post by asdf » Wed Mar 30, 2016 12:12 pm

Hi MGeorgiev,

Ranorex is based on the .Net framework, that means you can simply use C# methods in UserCodeModules.

Here is a little sample how this could work.
Bitmap img = new Bitmap("YourScreenshot.bmp");
for(int j = 0; j < img.Height; j++)
{
	for(int i = 0; i < img.Width; i++)
	{
		var color = img.GetPixel(i,j).Name;
		if(color == "ffff0000")
			Report.Failure("Fail");
		else
			Report.Success("Success");
	}
}
Regards,
asdf

MGeorgiev
Posts: 2
Joined: Tue Mar 29, 2016 4:51 pm

Re: Can I check for pixel's color in some area for validation

Post by MGeorgiev » Wed Mar 30, 2016 12:55 pm

Thank you asdf 8)