Solved Procedute to take a Print screen & Store in Data Item Using Blue Prism

cs.andras

Active Member
Hello,
Can anyone please help me in taking a Print screen & Store image in Data Item Using Blue Prism.
Thanks in Advance!!!
There is also a possibility through the Utilities BO, it's called Image manipulation I think. It's always a good idea to look around in those first.
 
@VJR,@cs.andras

Thanks for your Reply.

Is there any other way, other than using Application Modeller (Spying). I did not find any action in the Utilities BO, it's called Image manipulation.

Thanks,
Naveen.
 

VJR

Well-Known Member
Hi Naveen,

Is there any specific reason that you do not want to use the Application Modeller so that a suitable alternative can be thought of? Also post back what are you using - a windows based or a webpage or anything else.
 

cs.andras

Active Member
@VJR,@cs.andras

Thanks for your Reply.

Is there any other way, other than using Application Modeller (Spying). I did not find any action in the Utilities BO, it's called Image manipulation.

Thanks,
Naveen.
Did you import that BO? It's in BP's installation folder usually and has to be imported first.
 
@~VJ,
I am using 3 Reports-Excel, one Web based application. So if I use one Application Modeller it is failing for other Application Modeller. I need to capture error screen shot when the process is running for all these excel & Web based application.

@cs.andras

Yes, it is already there in the BP studio. What actions should I need to use to capture screen.
If possible, can you please show those with example.

Thanks in Advance!!!
 

VJR

Well-Known Member
Hi Naveen,

I got into developing this feature since a screenshot is required quite often by us. I believe that the ability to capture screenshot on errors is implemented in the version 6.
You can still explore the 'Image Manipulation' VBO and let me know if you find anything suitable.

Follow the below steps to create a new Action in the existing VBO:
Take a backup of 'Utility - Image Manipulation' xml file from the Blue Prism's VBO folder
1. Open the 'Initialise' tab -> 'Code Options' tab of the 'Utility - Image Manipulation'
- Add this path to the External References. (Must be at the same location but locate it on your machine)
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

2. Add a new tab and name it 'GetScreenshot' (or anything that you would like which shows in the Actions dropdown)
- Add a Code stage say 'Capture Screenshot'
- For the Start Input parameters of 'GetScreenshot', refer 1.jpg
- Refer 2.jpg for Input parameters of the Code stage
Add the necessary data items wherever required as you keep seeing them in the screenshots.
- Refer 3.jpg for Output parameters of the Code stage
- Add the below code in the 'Code' tab of the Code stage

Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics


area = My.Computer.Screen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture


- Refer 4.jpg for Output parameters of 'GetScreenshot'
- The overall 'Getscreenshot' tab looks like 5.jpg including all the required data items

3. Now, inside the process from where you want call this new Action
- Use an Action stage, choose the 'Utility - Image Manipulation', select the new Action 'GetScreenshot' from the dropdown (You need to Save and publish the VBO and hit Refresh or restart BP to reflect the new Action in the dropdown)
- Refer 6.jpg for the Input parameters of Action stage
- This is the path where the actual screenshot file will be saved. You need to make sure that the folders exists or can amend the code that checks if the folder exists and creates one if it doesn't. Note the backslash \ at the end of the path.
- Refer 7.jpg for the Output parameters of Action stage of Process call

4. The final output after running the process will look like this.

1522937205228.png

i. You will find an actual image stored in the Image data item - CapturedScreenshot data item
ii. Its full file path will be in the text data item - FullSavedScreenshotPath data item
iii. A physical image will be stored in the specified folder ie; "C:\Screenshots\" in this case.


The above steps saves the actual screenshot image in an Image data item as well as saves the image to a folder path.
You can tweak the code as per your requirements perhaps something like having a flag as True or False if you want the result to be stored only in an Image data item or only a physical image in a folder or both.

Edit: Screenshots stored under "C:\Screenshots\"
1526614529129.png

Also, the code is written such that the image is saved with the current date and time by default. If you want to customise that with the details of your running process, then that can be modified by passing a parameter to the code stage and modifying the .Save code and having a file name as required.
Similarly you can amend the code to save the image in the desired format - png, bmp ....and so on.
 

Attachments

  • 1. Start Properties - GetScreenshot action.JPG
    1. Start Properties - GetScreenshot action.JPG
    25.2 KB · Views: 1,070
  • 2. Code stage Input parameters.JPG
    2. Code stage Input parameters.JPG
    24.7 KB · Views: 1,033
  • 3. Code stage Output paramters.JPG
    3. Code stage Output paramters.JPG
    28.1 KB · Views: 961
  • 4. Output parameters of GetScreenshot.JPG
    4. Output parameters of GetScreenshot.JPG
    33.9 KB · Views: 898
  • 5. Overall GetScreenshot page.JPG
    5. Overall GetScreenshot page.JPG
    28.3 KB · Views: 875
  • 6. Action stage of Process call.JPG
    6. Action stage of Process call.JPG
    28.7 KB · Views: 929
  • 7. Output parameters of Action stage of Process call.JPG
    7. Output parameters of Action stage of Process call.JPG
    35.9 KB · Views: 792
Last edited:

cs.andras

Active Member
It was in BP before v6 as well, but not as an file-saving mechanism, but putting the image into a data item.
 

VJR

Well-Known Member
Hi cs.andras,

I made a mention about capturing screenshot on errors which I do not see in versions prior to 6. I've read the latest documentation of v6 and it has a
Robot Screen Capture feature where the Exception stages can now be set to save a screen capture. If there's already something like this then do let me know. The code that I have provided to Naveen although does not do this on error but is a response to the title of this thread.

I tried using the Image Manipulation but couldn't get a hold of it to capture a screenshot, so had to develop the above one. Just as Naveen requested to show as an example could you share how a screenshot can be captured using this VBO whenever you have some spare time.
 

mtabv

New Member
@VJR
thanks a lot for the description :)

I took the mentined steps bot got an error on the code. Could you help?

1524137558468.png

Thanks a lot :)

Mtabv
 

VJR

Well-Known Member
Hi mtabv,

ScreenshotImage is to be added as the output parameter as shown in attachment #3.
Also refer the comment stated above as - Add the necessary data items wherever required as you keep seeing them in the screenshots.
 

Raimundasv

New Member
@ VJR
Hi,
I'm trying tu use your code, I get this error
Internal : Could not execute code stage because exception thrown by code stage: A generic error occurred in GDI+.

If you have any ideas it would be great

RV
 

VJR

Well-Known Member
Hi Raimundasv,

I tried running the Screenshot code multiple times from a process but did not receive the error even once.
Also I modified the code to Save the image with the same name each time and then ran multiple times but that too did not reproduce the error.
So only you could try adding a fix and see what works for the error you are seeing.
On doing a web search on the error I found a few links with the error message which could occur while saving a bitmap.
http://blog.vishalon.net/bitmapsave-a-generic-error-occurred-in-gdi
Try the simpler one first that is mentioned in the very last of the above link about using Garbage Collector GC.Collect() or then try other options. Post back here with what fix you found to resolve the issue.
 

Raimundasv

New Member
Hi,
sloved the issue. The code and new VBO was all good. The problem was with the action stage and path. Thanks for giving a go at the fantom error :) with a clear head it's easier to spot mistakes.

RV
 
  • Like
Reactions: YGC

YGC

New Member
Hi,
sloved the issue. The code and new VBO was all good. The problem was with the action stage and path. Thanks for giving a go at the fantom error :) with a clear head it's easier to spot mistakes.

RV

Hi Raimundasv,

I get the same error "A generic error occurred in GDI+.", but i cannot see the problem with the action stage and path... Maybe mine is different, but.. could you please illuminate me?

Thank you very much, y
 

VJR

Well-Known Member
Hi YGC,

Raimundasv had the same error as yours but due to a different reason.
Did you get a chance to take a look at the different tentative solutions I provided to Raimundasv one post above.
 

YGC

New Member
Hi YGC,

Raimundasv had the same error as yours but due to a different reason.
Did you get a chance to take a look at the different tentative solutions I provided to Raimundasv one post above.


Hi, VJ

Thank you very much ! it worked. It was my mistake, i wasn't providing any value for the Folder path input
 
  • Like
Reactions: VJR

VJR

Well-Known Member
Capture Screenshot using Co-ordinates:

In line with the above post to capture the screenshot of an entire screen, below are some minor code changes to it for capturing a screenshot based on given co-ordinates.


1.jpg Process Diagram
2.jpg Object Diagram
3.jpg Start stage Input parameters
4.jpg Code stage Input parameters
5.jpg Code stage Output parameters
6.jpg End stage Output parameters

1.jpg and 2.jpg are the outputs generated after running this Object using the "eg;" parameters mentioned in the below code. (area = New Rectangle(200, 100, 800, 500)). The output image is slightly distorted at some portions and may require certain adjustments to the overall co-ordinates but below is good to start with.

Code stage:

Code:
Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics

area = New Rectangle(X, Y, Width, Height)
'Where X and Y are the coordinates, and Width and Height are the area to copy

'Eg; area = New Rectangle(200, 100, 800, 500)
'Pass the above parameters as an example to this Object and see what area of the screen
'it captures and then adjust them as per your requirement.

'If you see a black screen in the screenshot then the 'area to copy' is far out of the
'captured area given using X and Y co-ordinates. In that case, reduce the Width (if the black area
'is to the left or right) and adjust the Height (if it is at the top or bottom).

capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)

graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y , 0, 0, area.Size, CopyPixelOperation.SourceCopy)

FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture
 

Attachments

  • 1.Process Diagram.jpeg
    1.Process Diagram.jpeg
    57.2 KB · Views: 291
  • 2.Object Diagram.jpeg
    2.Object Diagram.jpeg
    65 KB · Views: 283
  • 3. Start stage Input parameters.JPG
    3. Start stage Input parameters.JPG
    39 KB · Views: 287
  • 4. Code stage Input parameters.JPG
    4. Code stage Input parameters.JPG
    33.1 KB · Views: 246
  • 5. Code stage Output parameters.JPG
    5. Code stage Output parameters.JPG
    27.4 KB · Views: 242
  • 6. End stage Output parameters.JPG
    6. End stage Output parameters.JPG
    35.6 KB · Views: 224

Ujjaldas

New Member
Hi Naveen,

I got into developing this feature since a screenshot is required quite often by us. I believe that the ability to capture screenshot on errors is implemented in the version 6.
You can still explore the 'Image Manipulation' VBO and let me know if you find anything suitable.

Follow the below steps to create a new Action in the existing VBO:
Take a backup of 'Utility - Image Manipulation' xml file from the Blue Prism's VBO folder
1. Open the 'Initialise' tab -> 'Code Options' tab of the 'Utility - Image Manipulation'
- Add this path to the External References. (Must be at the same location but locate it on your machine)
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

2. Add a new tab and name it 'GetScreenshot' (or anything that you would like which shows in the Actions dropdown)
- Add a Code stage say 'Capture Screenshot'
- For the Start Input parameters of 'GetScreenshot', refer 1.jpg
- Refer 2.jpg for Input parameters of the Code stage
Add the necessary data items wherever required as you keep seeing them in the screenshots.
- Refer 3.jpg for Output parameters of the Code stage
- Add the below code in the 'Code' tab of the Code stage

Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics


area = My.Computer.Screen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture


- Refer 4.jpg for Output parameters of 'GetScreenshot'
- The overall 'Getscreenshot' tab looks like 5.jpg including all the required data items

3. Now, inside the process from where you want call this new Action
- Use an Action stage, choose the 'Utility - Image Manipulation', select the new Action 'GetScreenshot' from the dropdown (You need to Save and publish the VBO and hit Refresh or restart BP to reflect the new Action in the dropdown)
- Refer 6.jpg for the Input parameters of Action stage
- This is the path where the actual screenshot file will be saved. You need to make sure that the folders exists or can amend the code that checks if the folder exists and creates one if it doesn't. Note the backslash \ at the end of the path.
- Refer 7.jpg for the Output parameters of Action stage of Process call

4. The final output after running the process will look like this.

View attachment 442

i. You will find an actual image stored in the Image data item - CapturedScreenshot data item
ii. Its full file path will be in the text data item - FullSavedScreenshotPath data item
iii. A physical image will be stored in the specified folder ie; "C:\Screenshots\" in this case.


The above steps saves the actual screenshot image in an Image data item as well as saves the image to a folder path.
You can tweak the code as per your requirements perhaps something like having a flag as True or False if you want the result to be stored only in an Image data item or only a physical image in a folder or both.

Edit: Screenshots stored under "C:\Screenshots\"
View attachment 805

Also, the code is written such that the image is saved with the current date and time by default. If you want to customise that with the details of your running process, then that can be modified by passing a parameter to the code stage and modifying the .Save code and having a file name as required.
Similarly you can amend the code to save the image in the desired format - png, bmp ....and so on.
Hi Naveen,

I got into developing this feature since a screenshot is required quite often by us. I believe that the ability to capture screenshot on errors is implemented in the version 6.
You can still explore the 'Image Manipulation' VBO and let me know if you find anything suitable.

Follow the below steps to create a new Action in the existing VBO:
Take a backup of 'Utility - Image Manipulation' xml file from the Blue Prism's VBO folder
1. Open the 'Initialise' tab -> 'Code Options' tab of the 'Utility - Image Manipulation'
- Add this path to the External References. (Must be at the same location but locate it on your machine)
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

2. Add a new tab and name it 'GetScreenshot' (or anything that you would like which shows in the Actions dropdown)
- Add a Code stage say 'Capture Screenshot'
- For the Start Input parameters of 'GetScreenshot', refer 1.jpg
- Refer 2.jpg for Input parameters of the Code stage
Add the necessary data items wherever required as you keep seeing them in the screenshots.
- Refer 3.jpg for Output parameters of the Code stage
- Add the below code in the 'Code' tab of the Code stage

Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics


area = My.Computer.Screen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture


- Refer 4.jpg for Output parameters of 'GetScreenshot'
- The overall 'Getscreenshot' tab looks like 5.jpg including all the required data items

3. Now, inside the process from where you want call this new Action
- Use an Action stage, choose the 'Utility - Image Manipulation', select the new Action 'GetScreenshot' from the dropdown (You need to Save and publish the VBO and hit Refresh or restart BP to reflect the new Action in the dropdown)
- Refer 6.jpg for the Input parameters of Action stage
- This is the path where the actual screenshot file will be saved. You need to make sure that the folders exists or can amend the code that checks if the folder exists and creates one if it doesn't. Note the backslash \ at the end of the path.
- Refer 7.jpg for the Output parameters of Action stage of Process call

4. The final output after running the process will look like this.

View attachment 442

i. You will find an actual image stored in the Image data item - CapturedScreenshot data item
ii. Its full file path will be in the text data item - FullSavedScreenshotPath data item
iii. A physical image will be stored in the specified folder ie; "C:\Screenshots\" in this case.


The above steps saves the actual screenshot image in an Image data item as well as saves the image to a folder path.
You can tweak the code as per your requirements perhaps something like having a flag as True or False if you want the result to be stored only in an Image data item or only a physical image in a folder or both.

Edit: Screenshots stored under "C:\Screenshots\"
View attachment 805

Also, the code is written such that the image is saved with the current date and time by default. If you want to customise that with the details of your running process, then that can be modified by passing a parameter to the code stage and modifying the .Save code and having a file name as required.
Similarly you can amend the code to save the image in the desired format - png, bmp ....and so on.
Hi VJ,
I am getting error for two variable (Now and Format). Is there any setting needs to be done . I put code - vb and added below path in external ref as advised.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

BP - 6
Windows 10

Can you please help me on this

View attachment 1531057261270.png
 
Top