Screenshot of multiple elements or defined area?

Class library usage, coding and language questions.
loonquawl2
Posts: 3
Joined: Tue Mar 03, 2020 12:05 pm

Screenshot of multiple elements or defined area?

Post by loonquawl2 » Mon May 03, 2021 1:14 pm

I'm currently using something like this to make Screenshots of elements in the AUT, to be saved to various paths, for later use (manual, etc.):

Code: Select all

public static void ScreenshotAndSave(Adapter AreaToShoot, string NameToSave)
		{
			
			Bitmap shotImage = Ranorex.Imaging.CaptureImage(AreaToShoot);
			shotImage.Save(NameToSave, System.Drawing.Imaging.ImageFormat.Png);
			
			
		}
My current issue with this is, that the AUT has no distinct element for the area i would like to take a screenshot of - my question: is it possible to 'combine' two elements to define an area to shoot?
I.e. screenshotting this Forum i would give the element of the 'Ranorex' logo on top, and the element of the search icon on the right, and expect as a screenshot the area defined by those two elements as seen here:
2021-05-03 14_06_56-Ranorex Forum - Post a new topic.png
2021-05-03 14_06_56-Ranorex Forum - Post a new topic.png (10.92 KiB) Viewed 31 times
Is there a nice way to do this?

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

Re: Screenshot of multiple elements or defined area?

Post by odklizec » Tue May 04, 2021 7:01 am

Hi,

I'm afraid, this would not be an easy task. You will have to write a method for combining two (or more) pictures together. You can see some code examples here:
https://www.codeproject.com/Articles/50 ... rmplusaplu
https://stackoverflow.com/questions/465 ... s-in-c-net
However, these examples only combine images together. What you will most probably have to do is, to get the position of each grabbed image and create a canvas of expected size of combined image (calculated from the size and position of both images) and finally place both images on the canvas. Sadly, I can't help you with that. Image manipulations are completely out of my programming skills ;)

What will be the purpose of such combined image? Just for report purposes?
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

loonquawl2
Posts: 3
Joined: Tue Mar 03, 2020 12:05 pm

Re: Screenshot of multiple elements or defined area?

Post by loonquawl2 » Tue May 04, 2021 10:01 am

Thanks odklizec, i was already experimenting with image manipulation, but i was getting fed up with the many stumbling stones on this path :-)

I now use two elements, that occupy diagonal corners of the rectangle (I call them upper left/lower right, but that is actually irrelevant) i would like to shoot (they do not need to overlap or touch each other) - and then i screenshoot the rectangle defined by these two. Sadly, i have to deactivate the progress dialog, because the CaptureDesktopImage function will not ignore it (as the CaptureElement does).

Code: Select all

[UserCodeMethod]
		public static void RectangleAndSave(Adapter UpperLeft, Adapter LowerRight, string PathAndNameToSave)
		{
			Rectangle rectToShoot = Rectangle.Union(UpperLeft.ScreenRectangle, LowerRight.ScreenRectangle);
			Bitmap shotImage = Ranorex.Imaging.CaptureDesktopImage(rectToShoot);
			shotImage.Save(PathAndNameToSave, System.Drawing.Imaging.ImageFormat.Png);
		}

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

Re: Screenshot of multiple elements or defined area?

Post by odklizec » Tue May 04, 2021 10:04 am

Hi,

Cool, it looks pretty easy. Thanks for sharing the solution!
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