HEA HEA -4 years ago 86
Vb.net Question

How to use the "PictureBox.Image.Flags" property?

I'm programming a picture viewer in Visual Basic.NET in Visual studio 2017 RC. In my form, I'm using a picture box that is named "PictureBox". I was trying to get information about the picture displayed inside the picture box using the PictureBox.Image.Flags property so the user can view these information.

But it seems very difficult to work with this property as it returns a value (let's call this the main value) that is a sum of other values (image flags, they are integer numbers and they represent information about the picture's pixel data and this is what I want to display). That said, I have to know the combination of image flags that sum to the main value.
For example (not applicable):

The main value of the property is 10 and the available image flags are: 2, 4, 6.

In this case, the image flags "4" and "6" sum to "10". So I will display the information that they represent to the user.

The problem is that there are 14 image flags with varying values and a picture can have more than one of these image flags (visit the second link to see the image flags, what they represent and their values).

This is some of my code right now (there is more :D):

' This function returns a value based on the PictureBox.Image.Flags property's value.
Function GetFlags()
If PictureBox.Image.Flags = 1 Then
Return 1
End If
If PictureBox.Image.Flags >= 2 Then
Return 2
End If
If PictureBox.Image.Flags >= 4 Then
Return 3
End If
If PictureBox.Image.Flags >= 8 Then
Return 4
End If
' Update the "PictureInfo" variable based on the vlaue the "GetFlags()" function returns.
If GetFlags() = 1 Then
PictureInfo += Environment.NewLine & "• Scalable: yes."
End If
If GetFlags() = 2 Then
PictureInfo += Environment.NewLine & "• Scalable: yes." &
Environment.NewLine & "• Has aplha: yes."
End If
If GetFlags() = 3 Then
PictureInfo += Environment.NewLine & "• Scalable: yes." &
Environment.NewLine & "• Has aplha: yes." &
Environment.NewLine & "• Has translucent: yes."
End If
If GetFlags() = 4 Then
PictureInfo += Environment.NewLine & "• Partially scalable: yes." &
Environment.NewLine & "• Has aplha: yes." &
Environment.NewLine & "• Has translucent: yes."
End If


What is the right and most efficient way of using this property? If it won't work, is there another way of representing the image flags information without using this property?

About the property: https://msdn.microsoft.com/en-us/library/system.drawing.image.flags(v=vs.110).aspx?cs-save-lang=1&cs-langenter code here=vb#code-snippet-1

About image flags:https://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageflags(v=vs.110).aspx

Answer Source

to test individual flags use the And function

    If (PictureBox1.Image.Flags And System.Drawing.Imaging.ImageFlags.ColorSpaceGray) <> 0 Then

or Multiples

Imports System.Drawing.Imaging.ImageFlags


If (PictureBox1.Image.Flags And (ColorSpaceGray + ColorSpaceRgb)) <> 0 Then

Alternative

Imports System.Drawing.Imaging
Imports System.Drawing.Imaging.ImageFlags

If CType(PictureBox1.Image.Flags, ImageFlags).HasFlag(ColorSpaceGray) then

Or multiples

If CType(PictureBox1.Image.Flags, ImageFlags).HasFlag(CType(ColorSpaceGray  + ColorSpaceRgb, ImageFLags)) then
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download