So I have a folder full of images, I need to crop them to 3:2 aspect ratio.
I managed to create a code and used the Invoke code activity, that seems to do the job but not in a way I want it.
Dim originalImage As New Bitmap(OriginalImage)
' Calculate the new width and height for a 3:2 aspect ratio
Dim newWidth As Integer = CInt(originalImage.Height * 3 / 2)
Dim newHeight As Integer = CInt(originalImage.Height)
' Create a new bitmap with the calculated dimensions
Dim croppedImage As New Bitmap(newWidth, newHeight)
' Create a graphics object and draw the original image onto the new bitmap
Using g As Graphics = Graphics.FromImage(croppedImage)
g.DrawImage(originalImage, New Rectangle(0, 0, newWidth, newHeight), New Rectangle(0, 0, originalImage.Width, originalImage.Height), GraphicsUnit.Pixel)
End Using
' Set compression quality (0-100, where 100 is best quality)
Dim quality As Integer = 90
' Save the cropped image with compression
croppedImage.Save(CroppedImage, Imaging.ImageFormat.Jpeg)
Here OriginalImage & CroppedImage are two arguments.
The problem with the code:
- Instead of cropping it is directly changing the image size by stretching and thickening, and then the image is looking ugly.
- It’s not letting me save it to the same image file, bound to create a copy.
Can anyone help with another way or fix my code? TIA