How to resize Image in UiPath

#Usecase- Many times we encountered the situation where we take screenshot of the image but the screenshot is not captured as we desire and we need to resize the image.

Lets see how we can implement this in UiPath.

Step 1:- We will use the Take screenshot activity to capture the image and store the result in a variable .Let’s say ImageOutput
image

This is the filename that I have used for this example.

Step 2:- We will now use the Assign activity and pass the dimensions of the image that we require & store the output in a variable regionCropping.

#Syntax:-

New uipath.core.Region(New Rectangle(x,y,height,width)

Step 3:- We will now use another Assign activity and use the below code.

This code will crop the image as per the above dimensions.

Step 4:- Finally,we will use Save Image activity to save our image in the network drive.
image

I hoped you enjoyed the article.

Happy Automation!!!

3 Likes

Hi @Nitya1,

Thank you for sharing.

Hey! @Nitya1 ,

Thanks for sharing…

It’s better to show us the type of the Variables which we used in this use case…

Useful information…

Thanks again

Regards,
NaNi

Hi @THIRU_NANI

I will share the type of variables I used in this case.

1 Like

Here, are the types of variables used to resize the image.

1 Like

Hey, thank you a lot for sharing this.

But I have a real problem getting this to work properly.

Rectangle: New uipath.core.Region(New Rectangle(20, 85, 1040, 600))

Crop: ImageToCrop.CropImage(regionCropping , , False,)

This does give me an image of size 600x200 (Original:3456*1416)

While, if I use some code for it, it gives me the right size, but takes a bit longer:

Dim CropRect As New Rectangle(20, 85, 1040, 600)
Dim OriginalImage = System.Drawing.Image.FromFile(in_fileNameIn)
Dim CropImage = New Bitmap(CropRect.Width, CropRect.Height)
Using grp = Graphics.FromImage(CropImage)
grp.DrawImage(OriginalImage, New Rectangle(0, 0, CropRect.Width, CropRect.Height), CropRect, GraphicsUnit.Pixel)
OriginalImage.Dispose()
CropImage.Save(In_fileNameOut)
End Using

Any ideas or suggestions welcome