Posts

Showing posts from June, 2014

Retrieves The Default User's Directory Path

 Introduction To receive the path of the user's default directory, the following function(s) may be applied.     Public Shared Function GetDefaultDirectory() As String         Dim txt As String = ""         Dim paths As String() = Environment.GetFolderPath(Environment.SpecialFolder.Personal).Split(New Char() {"\"c})         For i As Integer = 0 To paths.Length - 2             txt = txt & paths(i) & "\"         Next         Dim defaultDirectory As String = Nothing         Try             If Not Directory.Exists(txt) Then                 Directory.CreateDirectory(txt)             End If             defaultDirectory = txt         Catch ex As Exception             If TypeOf ex Is IOException AndAlso TypeOf ex Is UnauthorizedAccessException AndAlso TypeOf ex Is ArgumentException Then                 defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal)             End If         End Try         Return defaultDirectory  

Detect Image is upside Down

The following function may used to detect if an image is upside down or not. The function will check the BitmapData.Stride value and returned value is of a Boolean type and if the returned value of BitmapData.Stride is greater than zero...then the bitmap is upside down. For further details about BitmapData Class, please check the link Link Function:     Private Function IsUpSideDownBitmap(originalBitmap As Bitmap) As Boolean         Dim bmp As Bitmap = CType(originalBitmap.Clone(), Bitmap)         Dim rect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)         Dim bmpData As Imaging.BitmapData = bmp.LockBits(rect, Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppArgb)         Return originalBitmap IsNot Nothing AndAlso bmpData.Stride > 0     End Function Usage:          ' Define the image         Dim bmp As New Bitmap(My.Resources._29322)         ' pass the image to the function        If IsUpSideDownBitmap(bmp) Then            ' If re