Dim upWidth As Integer = upBmp.Width
Dim upHeight As Integer = upBmp.Height
Dim newX As Integer = 0
Dim newY As Integer = 0
Dim reDuce As Decimal
If Val(Redty) = 1 Then
reDuce = Rval / 100
ElseIf Val(Redty) = 2 Then
reDuce = Val(Rval) / upWidth
ElseIf Val(Redty) = 3 Then
reDuce = Val(Rval) / upHeight
Else
MessageBox.Show("Enter the Final Size of Image", "Image Optimizer")
Exit Sub
End If
newHeight = upHeight * reDuce
newWidth = upWidth * reDuce
WRITEFILE(CStr(newHeight & " : " & newWidth))
Dim newBmp As Bitmap = New Bitmap(newWidth, newHeight, Imaging.PixelFormat.Format24bppRgb)
newBmp.SetResolution(72, 72)
Dim newGraphic As Graphics = Graphics.FromImage(newBmp)
Try
newGraphic.Clear(Color.White)
newGraphic.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
newGraphic.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
newGraphic.DrawImage(upBmp, newX, newY, newWidth, newHeight)
If Len(WaterMark) > 0 Then
Dim font As Font = New Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Pixel)
Dim color As Color = color.FromArgb(transp, 0, 0, 0) '; //Adds a black watermark with a low alpha value (almost transparent).
Dim atPoint As Point = New Point(100, 100)
' Point atPoint = new Point(100, 100); //The pixel point to draw the watermark at (this example puts it at 100, 100 (x, y)).
Dim brush As SolidBrush = New SolidBrush(color)
newGraphic.DrawString(WaterMark, font, brush, atPoint)
End If
If ext.ToLower = "png" Then
newBmp.Save(filePath, Imaging.ImageFormat.Png)
ElseIf ext.ToLower = "jpg" Then
newBmp.Save(filePath, Imaging.ImageFormat.Jpeg)
ElseIf ext.ToLower = "tif" Then
newBmp.Save(filePath, Imaging.ImageFormat.Tiff)
End If
'filePath = Replace(filePath, ".png", ".jpg")
'newBmp.Save(filePath, Imaging.ImageFormat.Jpeg)
'filePath = Replace(filePath, ".jpg", ".tif")
'newBmp.Save(filePath, Imaging.ImageFormat.Tiff)