''' <summary>
''' Resize the target image, save it to new location and delete old one.
''' </summary>
''' <param name="strFileName">Original/Source File Name.</param>
''' <remarks>
''' Imports System.IO at the beginning.
''' This is tested and work well on Windows CE 5.0 based HandHeld Terminals only.
''' Not tested in another platform yet.
''' </remarks>
''' <Owner>By SCSFDEV @ March 10, 2009 (9:55 AM)</Owner>
Private Sub ResizeNMoveImage(ByVal strFileName As String)
Try
' Create a bitmap file for original image.
Dim srcmap As New Bitmap(strFileName)
' This is where the new image will temp stored. 150x150.
Dim destbit As New Bitmap(150, 150)
' The size of the source image.
Dim srcRec As New Rectangle(0, 0, srcmap.Width, srcmap.Height)
' The size of the destination image.
Dim destRec As New Rectangle(0, 0, 150, 150)
' Start a graphics whose host is new bitmap.
Dim g As Graphics
g = Graphics.FromImage(destbit)
' Load image in graphics.
g.DrawImage(srcmap, destRec, srcRec, GraphicsUnit.Pixel)
' Define the destination target location file path.
Dim strPath As String = ""
strPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
' Save the new image to the above location with whatever file name you want.
' Eg > "Your application path\image\a.jpeg".
' or > "Program Files\[application name]\image\a.jpeg".
destbit.Save(strPath & "\image\a.jpeg", Imaging.ImageFormat.Jpeg)
' If Old file exist?
If File.Exists(strFileName) Then
' Delete it.
File.Delete(strFileName)
End If
Catch ex As Exception
' If there is some exception, Show it on screen. (Not recommented for End user.
' Should display some message instead of this ex.message and should write to Log file for developers to debug.)
MessageBox.Show(ex.Message, "Error@ResizeNMoveImage", MessageBoxButtons.OK, MessageBoxIcon.Hand, _
MessageBoxDefaultButton.Button1)
End Try
End Sub