Playing With Screenshots and Clipboard Images – Blue Prism

Blue Prism doesn’t have a native way of taking any image from clipboard and save it as a file on disk .

How cool it would have been to pick up an image from clipboard and store it in data item directly?

Watch the video which demonstrates the same.

 

 

Please read below and use the code provided to do the following:

Prerequisites:

DLL Files to be imported :

System.Drawing.dll

mscorlib.dll

System.IO.FileSystem.dll

Name Spaces required:

System.Drawing

System.Drawing.Imaging

System.IO

Save Image from Clipboard to Image File on Disk:

The below piece of code can be put in the Global Code area and then referenced from code stage to save any image that’s in clipboard to disk in any of the known image formats . I.E. Jpeg, Bmp, Gif, Png, Tiff, Exif, Wmf.

Code:

private void saveScreenshot(string director, string nume, string format)
{
if (Clipboard.GetDataObject() != null)
{
IDataObject data = Clipboard.GetDataObject();

if (data.GetDataPresent(DataFormats.Bitmap))
{
Image image = (Image)data.GetData(DataFormats.Bitmap, true);
switch (format)
{
case “Jpeg”:
{
image.Save(director + “\\” + nume + “.” + format, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
}
case “Bmp”:
{
image.Save(director + “\\” + nume + “.” + format, System.Drawing.Imaging.ImageFormat.Bmp);
break;
}
case “Gif”:
{
image.Save(director + “\\” + nume + “.” + format, System.Drawing.Imaging.ImageFormat.Gif);
break;
}
case “Png”:
{
image.Save(director + “\\” + nume + “.” + format, System.Drawing.Imaging.ImageFormat.Png);
break;
}
case “Tiff”:
{
image.Save(director + “\\” + nume + “.” + format, System.Drawing.Imaging.ImageFormat.Tiff);
break;
}
case “Exif”:
{
image.Save(director + “\\” + nume + “.” + format, System.Drawing.Imaging.ImageFormat.Exif);
break;
}
case “Wmf”:
{
image.Save(director + “\\” + nume + “.” + format, System.Drawing.Imaging.ImageFormat.Wmf);
break;
}
}

}
}
else
{
//return false;
}
}

Use the below line to be used in code stage : 

saveScreenshot(Directory,FileName,Format);

Inputs: Directory where the file will be saved, Filename , The format which you want to save.

 

Take a screenshot of robot and Save on Disk:

The below piece of code can be placed in global code to Take a screenshot of the screen on the executing robot and save it directly on disk to be used afterwards.

Code:

private void PrintScreen(string filename)

{

Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

Graphics graphics = Graphics.FromImage(printscreen as Image);

graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);

printscreen.Save(filename, ImageFormat.Jpeg);

}

Use the below line to be used in code stage : 

PrintScreen(Filename);

Inputs: The Entire Filename with full path where you want to store the screenshot.

The Full Utility Object can be found HERE

Download Link:


Please follow and like us: