cancel
Showing results for 
Search instead for 
Did you mean: 

How to save image data type (Data item) to desktop folder png format?

ÖzençGezgin
Level 4
I have an image data type (Data item) . I want to save this file to desktop folder. How can it be?
13 REPLIES 13

Nice one, so basically a method that could also be used to take screenshots to some degree. Surface Automation to read images (can be set to location based to ignore what the image is) and then write binary to save.

------------------------------
Ben Lyons
Product Consultant
Blue Prism
UK
------------------------------
Ben Lyons
Principal Product Specialist - Decipher
SS&C Blue Prism
UK based

Hi @Ben.Lyons1

I went back and re-read what you were saying. I see that you were talking about taking an actual image data item and saving that to the disk. What I suggested doesn't work directly for that. Just wanted to follow up and say that yeah it cannot be directly saved. You'd have to convert from Image to Binary first.

I grabbed some code from Stack Overflow to test it just in case and it works: ​https://stackoverflow.com/questions/3801275/how-to-convert-image-to-byte-array

I did adjust the code slightly because I'm lazy. 😃 (I added static so I didn't have to instantiate an object when using it)

Here's the Global Code:
public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
   using (var ms = new MemoryStream())
   {
      imageIn.Save(ms,imageIn.RawFormat);
      return  ms.ToArray();
   }
}​

And then here's what would be in a code stage, assuming an input parameter of ImageIn and an output parameter of BinaryOut
BinaryOut = ImageToByteArray(ImageIn);​

And in case anyone is trying this who isn't familiar with programming, be sure to add Namespace imports in the Initialise page > Properties > Code Options > Namespace Imports. For this, you should only have to add System.IO for the MemoryStream. No additions needed in External References.

Edit: Also in case it's not obvious, at this point, the Utility - File Management VBO's action 'Write Binary Data' can be used to write the binary data to the disk. Use the file extension such as .png in the name of the new file. And then the image should be viewable.

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------


Dave Morris, 3Ci at Southern Company

Nice one. Looks good.

------------------------------
Ben Lyons
Product Consultant
Blue Prism
UK
------------------------------
Ben Lyons
Principal Product Specialist - Decipher
SS&C Blue Prism
UK based

Hi Dave,

   That worked great.  Initially, we had a Data Item of type Image, and didn't readily see a way to Write it out to a file using a VBO.

Once we updated the logic such that the Screen Shot that were were working with was in a Data Type of Binary, then, as you pointed out, we could simply use the Utility File Mgmt VBO, Write Binary Data Action to write it out to a file.

 Thanks

------------------------------
Kevin Wilson
`Solution Engineer
Blueprism
America/Denver
------------------------------