|
Imports System.IO
Public Class frmResize
Public strSource As String
Public strDestination As String
Public Function ImageResize(ByVal strImageSrcPath As String _
, ByVal strImageDesPath As String _
, Optional ByVal intWidth As Integer = 0 _
, Optional ByVal intHeight As Integer = 0) As String
If System.IO.File.Exists(strImageSrcPath) = False Then Exit Function
Dim objImage As System.Drawing.Image = System.Drawing.Image.FromFile(strImageSrcPath)
If intWidth > objImage.Width Then intWidth = objImage.Width
If intHeight > objImage.Height Then intHeight = objImage.Height
If intWidth = 0 And intHeight = 0 Then
intWidth = objImage.Width
intHeight = objImage.Height
ElseIf intHeight = 0 And intWidth <> 0 Then
intHeight = Fix(objImage.Height * intWidth / objImage.Width)
ElseIf intWidth = 0 And intHeight <> 0 Then
intWidth = Fix(objImage.Width * intHeight / objImage.Height)
End If
Dim imgOutput As New Bitmap(objImage, intWidth, intHeight)
Dim imgFormat = objImage.RawFormat
objImage.Dispose()
objImage = Nothing
If strImageSrcPath = strImageDesPath Then System.IO.File.Delete(strImageSrcPath)
' send the resized image to the viewer
imgOutput.Save(strImageDesPath, imgFormat)
imgOutput.Dispose()
Return strImageDesPath
End Function
Private Sub ButtonBrowseSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBrowseSource.Click
With OpenFileDialog1
.ShowDialog()
strSource = .FileName
TextBox1.Text = strSource
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With SaveFileDialog1
.ShowDialog()
strDestination = .FileName
TextBox2.Text = strDestination
End With
End Sub
Private Sub ButtonResize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonResize.Click
If strSource <> vbNullString _
And strDestination <> vbNullString _
And TextBoxHeight.Text <> vbNullString _
And TextBoxWidth.Text <> vbNullString Then
If (Me.ImageResize( _
strSource _
, strDestination _
, CInt(TextBoxWidth.Text) _
, CInt(TextBoxHeight.Text))) <> "" Then
MsgBox("Resize completed.", MsgBoxStyle.Information)
Else
MsgBox("Error", MsgBoxStyle.Critical)
End If
End If
End Sub
Private Sub frmResize_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.