I tried cropping an image, could not do it. So instead I choose to make a new image.
The below text is the thinking process I used to complete the tasks, which I think is the closest you will get, without using Photoshop or something. I'm sure someone out there has a better solution than mine here.
You have to upload the image fist,
take a peek at the size of the uploaded image,
then get it's size, consider the aspect ratio for calculating
Draw a canvas, set the back color
create a new image based on the uploaded image size, make sure it's smaller than the target size
Set the new image in the canvas
Save the image
Peek at the image
Dim fs As FileStream = New FileStream(p_PhysicalPath, FileMode.Open, FileAccess.Read)
Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(fs)
iWidth = image.Width
iHeight = image.Height
Once you have your calculations, you then create the new image. Take note of how you can get tons of information from an image such at the color of every pixel in the image by knowing the pixel location.
Sample code to examine
Dim sourceFile As Drawing.Bitmap = Nothing
Dim convertedfile As Drawing.Bitmap = Nothing
Dim newGraphic As Drawing.Graphics = Nothing
'Create a brand new image, for preview purposes
Try
Dim staticBGColor As Drawing.Color = System.Drawing.Color.White
Dim peekImage As Drawing.Bitmap = New Drawing.Bitmap(p_PhysicalPath, True)
Dim bgColor As System.Drawing.Color = peekImage.GetPixel(1, 1) <- Take Note
peekImage.Dispose()
peekImage = Nothing
convertedfile = New Drawing.Bitmap(cWidth, cHeight,Drawing.Imaging.PixelFormat.Format24bppRgb)
convertedfile.SetResolution(72, 72)
convertedfile.MakeTransparent()
newGraphic = Drawing.Graphics.FromImage(convertedfile)
newGraphic.SmoothingMode = Drawing.Drawing2D.SmoothingMode.Default
newGraphic.InterpolationMode = Drawing.Drawing2D.InterpolationMode.High
newGraphic.Clear(bgColor)
sourceFile = Drawing.Bitmap.FromFile(p_PhysicalPath)
newGraphic.DrawImage(sourceFile, newX, newY, newWidth, newHeight)
convertedfile.Save(nPhysicalPath, Drawing.Imaging.ImageFormat.Jpeg)
Catch ex As Exception
End Try
newGraphic.Dispose()
convertedfile.Dispose()
sourceFile.Dispose()