Introduction
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 this 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
Using the Code
Dim bmp As New Bitmap(My.Resources._29322)
If IsUpSideDownBitmap(bmp) Then
e.Graphics.DrawImage(bmp, 0, 0)
End If