How to convert image to byte array?

Class library usage, coding and language questions.
espekkaya
Posts: 12
Joined: Tue Mar 11, 2014 4:07 pm

How to convert image to byte array?

Post by espekkaya » Tue Mar 25, 2014 3:19 pm

My working Project which I code, is created barcode code. And I want to validate the image. As you know that barcode image changes every time but size never change.

So at Ranorex How to covert image to byte array?

Thank you in advanced...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to convert image to byte array?

Post by Support Team » Thu Mar 27, 2014 2:26 pm

Hello espekkaya,

Unfortunately I’m not exactly sure what you want to do. Please provide additional information on how your compare should look like.

Regards,
Robert
.
Image

espekkaya
Posts: 12
Joined: Tue Mar 11, 2014 4:07 pm

Re: How to convert image to byte array?

Post by espekkaya » Wed Apr 02, 2014 9:17 am

Hello,

Shortly I want to get size of image at my repository. so I compare size of images.

Thank you.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to convert image to byte array?

Post by Support Team » Fri Apr 04, 2014 2:09 pm

Hello espekkaya,

Unfortunately it’s not possible to retrieve the files size of the screenshot elements since they are stored in the *.rximgres and not separately as bitmap files.

In order to overcome this issue I suggest saving the screenshots as bitmap files to your disk. After that you can access the file via the FileInfo-Class which is provided by the System.IO assembly. The FileInfo-Class provides the FileInfo.Length property which returns the size of the current file in bytes.

For further information concerning the FileInfo-Class, please visit: http://msdn.microsoft.com/en-us/library ... .110).aspx

Regards,
Robert
.
Image

espekkaya
Posts: 12
Joined: Tue Mar 11, 2014 4:07 pm

Re: How to convert image to byte array?

Post by espekkaya » Mon Apr 07, 2014 7:47 am

Thank you for your response.

I have an other solution.

Here is my code;

Code: Select all

        	try
        	{
				var webClient = new WebClient();
				byte[] imageBytes = webClient.DownloadData(repo.myItemsPath.myItemImage.Src.Trim());
				
				Validate.IsTrue((imageBytes.LongLength == 0) ? false : true);
				Report.Success("Control", "Image exists.");
        	}
        	catch(Exception ex)
        	{
        		Validate.IsTrue(false);
        		
        		Report.Warn("Control", "Image does not exist.");
        	}
I Hope that it is useful.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to convert image to byte array?

Post by Support Team » Tue Apr 08, 2014 1:05 pm

Hello espakkaya,

I'm glad that you found a solution. Thank you for sharing your code.

Regards,
Robert
.
Image