Check if bitmap pixel data contains alpha information.

While reading this topic Image.GetFlags method  (the topic was written in C language) , I came with  a solution to check if the bitmap or image pixel data contains alpha information,

In Dot Net to gets flags that indicate certain attributes of an Image , simply check the value of Flags property which will return a bitwise combination of ImageFlags.

The following Function shows how to check bitmap alpha information.


Code:

    Public Shared Function IsHasAlpha(bmp As Bitmap) As Boolean
        Return bmp IsNot Nothing AndAlso (bmp.Flags And Imaging.ImageFlags.HasAlpha) > Imaging.ImageFlags.None
    End Function


Usage:

1 - Define a bitmap.
2 - Pass the bitmap value to the above function, and if the image has alpha information the function  shall returned True
  
  If IsHasAlpha(bmp) Then
    ' Do something
  End If


References:

GetFlags Method
Image Flags Property
ImageFlags Enumeration

Comments

Popular posts from this blog

مقدمة الي تشفير الحروف الأبجدية العربية

VB.NET Translucent Control using GDI+

Add Custom Event to a Class in VB.NET