VB.NET BMP File Header - PeatSoft



Option Explicit On
Option Strict On

Imports System.IO

Friend Module BMP

    Private Structure BITMAP_FILEHEADER
        Friend Signature As String
        Friend Size As UInteger
        Friend Reserved As UInteger
        Friend BitsOffset As UInteger
    End Structure

    Private Structure BITMAP_INFOHEADER
        Friend HeaderSize As UInteger
        Friend Width As Integer
        Friend Height As Integer
        Friend Planes As UShort
        Friend BitCount As UShort
        Friend Compression As UInteger
        Friend SizeImage As UInteger
        Friend PelsPerMeterX As Integer
        Friend PelsPerMeterY As Integer
        Friend ClrUsed As UInteger
        Friend ClrImportant As UInteger
    End Structure

    Private Structure _Os2BmpArrayHeader
        Friend Type As UShort
        Friend Size As UInteger
        Friend OffsetToNext As UInteger
        Friend ScreenWidth As UShort
        Friend ScreenHeight As UShort
    End Structure

    Private Structure _Os2BmpFileHeader
        Friend FileType As UShort
        Friend FileSize As UInteger
        Friend XHotSpot As UShort
        Friend YHotSpot As UShort
        Friend BitmapOffset As UInteger
    End Structure

    Private Structure BITMAP_COREHEADER
        Friend Width As UShort
        Friend Height As UShort
        Friend Planes As Short
        Friend BitCount As Short
    End Structure

    Private Structure BITMAPV4HEADER
        Friend bV4Size As UInteger
        Friend bV4Width As Integer
        Friend bV4Height As Integer
        Friend bV4Planes As UShort
        Friend bV4BitCount As UShort
        Friend bV4V4Compression As UInteger
        Friend bV4SizeImage As UInteger
        Friend bV4XPelsPerMeter As Integer
        Friend bV4YPelsPerMeter As Integer
        Friend bV4ClrUsed As UInteger
        Friend bV4ClrImportant As UInteger
        Friend bV4RedMask As UInteger
        Friend bV4GreenMask As UInteger
        Friend bV4BlueMask As UInteger
        Friend bV4AlphaMask As UInteger
        Friend bV4CSType As UInteger
        Friend bV4RedX As Integer
        Friend bV4RedY As Integer
        Friend bV4RedZ As Integer
        Friend bV4GreenX As Integer
        Friend bV4GreenY As Integer
        Friend bV4GreenZ As Integer
        Friend bV4BlueX As Integer
        Friend bV4BlueY As Integer
        Friend bV4BlueZ As Integer
        Friend bV4GammaRed As UInteger
        Friend bV4GammaGreen As UInteger
        Friend bV4GammaBlue As UInteger
    End Structure

    Private Structure BITMAPV5HEADER
        Friend bV4Size As UInteger
        Friend bV4Width As Integer
        Friend bV4Height As Integer
        Friend bV4Planes As UShort
        Friend bV4BitCount As UShort
        Friend bV4V4Compression As UInteger
        Friend bV4SizeImage As UInteger
        Friend bV4XPelsPerMeter As Integer
        Friend bV4YPelsPerMeter As Integer
        Friend bV4ClrUsed As UInteger
        Friend bV4ClrImportant As UInteger
        Friend bV4RedMask As UInteger
        Friend bV4GreenMask As UInteger
        Friend bV4BlueMask As UInteger
        Friend bV4AlphaMask As UInteger
        Friend bV4CSType As UInteger
        Friend bV4RedX As Integer
        Friend bV4RedY As Integer
        Friend bV4RedZ As Integer
        Friend bV4GreenX As Integer
        Friend bV4GreenY As Integer
        Friend bV4GreenZ As Integer
        Friend bV4BlueX As Integer
        Friend bV4BlueY As Integer
        Friend bV4BlueZ As Integer
        Friend bV4GammaRed As UInteger
        Friend bV4GammaGreen As UInteger
        Friend bV4GammaBlue As UInteger
        Friend bV5Intent As UInteger
        Friend bV5ProfileData As UInteger
        Friend bV5ProfileSize As UInteger
        Friend bV5Reserved As UInteger
    End Structure

    Private Structure Os22xBitmapHeader
        Friend HeaderSize As UInteger
        Friend Width As UInteger
        Friend Height As UInteger
        Friend Planes As UShort
        Friend BitCount As UShort
        Friend Compression As UInteger
        Friend ImageDataSize As UInteger
        Friend XResolution As UInteger
        Friend YResolution As UInteger
        Friend ColorsUsed As UInteger
        Friend ColorsImportant As UInteger
        Friend Units As UShort
        Friend Reserved As UShort
        Friend Recording As UShort
        Friend Rendering As UShort
        Friend Size1 As UInteger
        Friend Size2 As UInteger
        Friend ColorEncoding As UInteger
        Friend Identifier As UInteger
    End Structure

    Private Structure TagRGBQUAD
        Friend rgbBlue As Byte
        Friend rgbGreen As Byte
        Friend rgbRed As Byte
        Friend rgbReserved As Byte
    End Structure

    Private Structure TagRGBTRIPLE
        Friend rgbtBlue As Byte
        Friend rgbtGreen As Byte
        Friend rgbtRed As Byte
    End Structure

    Private reader1 As BinaryReader
    Private isError As Boolean
    Private BMPtype As Integer
    Private ColorCount As UInteger
    Private ColorOffset As Integer

    Private BitmapFileHeader As BITMAP_FILEHEADER
    Private BitmapInfoHeader As BITMAP_INFOHEADER
    Private BitmapCoreHeader As BITMAP_COREHEADER
    Private Bitmap_V4Header As BITMAPV4HEADER
    Private Bitmap_V5Header As BITMAPV5HEADER
    Private Os2_2xBitmapHeader As Os22xBitmapHeader
    Private Os2BmpFileHeader As _Os2BmpFileHeader
    Private Os2BmpFileHeader2 As _Os2BmpFileHeader
    Private Os2_2xBitmapHeader2 As Os22xBitmapHeader
    Private Os2BmpArrayHeader As _Os2BmpArrayHeader

    Public Function GetBMPSignature(FilePath As String) As String
        reader1 = New BinaryReader(File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))

        Dim Buffer(1) As Byte
        Dim count As Integer
        count = reader1.Read(Buffer, 0, 2)
        Dim BMPsig As String
        BMPsig = Text.Encoding.Default.GetString(Buffer)
        reader1.BaseStream.Position = 2
        ReDim Form1.rgb(2, 256)

        Dim ftext As String
        Select Case BMPsig
            Case "BM"
                ftext = "Windows Bitmap" + vbNewLine + vbNewLine + BMPView(FilePath, 0)
            Case "BA"
                ftext = "OS/2 Bitmap Array" + vbNewLine + vbNewLine + BAView(FilePath)
            Case = "CI"
                ftext = "OS/2 Color Icon" + vbNewLine + vbNewLine + CIView(FilePath, 0)
            Case = "CP"
                ftext = "OS/2 Color Pointer" + vbNewLine + vbNewLine
            Case = "IC"
                ftext = "OS/2 Icon" + vbNewLine + vbNewLine
            Case "PT"
                ftext = "OS/2 Pointer" + vbNewLine + vbNewLine
            Case Else
                ftext = "no Bitmap!"
        End Select

        GetBMPSignature = ftext
    End Function

    Public Function BMPView(FilePath As String, offset2 As Integer) As String

        ColorCount = 0
        BMPView = GetBMPHeader(0, offset2)

        If isError = True Then
            Exit Function
        End If

    End Function

    Public Function CIView(FilePath As String, offset2 As Integer) As String

        ColorOffset = 0
        CIView = GetBMPHeader(1, offset2)

        If isError = True Then
            Exit Function
        End If

        reader1.BaseStream.Position = reader1.BaseStream.Position + 2
        CIView = CIView + vbNewLine + GetBMPHeader(1, 0)

    End Function

    Public Function BAView(FilePath As String) As String
        Dim ftext As String = ""
        Dim lOffset As Integer

        Do
            Os2BmpArrayHeader.Size = reader1.ReadUInt32
            Os2BmpArrayHeader.OffsetToNext = reader1.ReadUInt32
            Os2BmpArrayHeader.ScreenWidth = reader1.ReadUInt16
            Os2BmpArrayHeader.ScreenHeight = reader1.ReadUInt16

            Dim Buffer(1) As Byte
            Dim count As Integer
            count = reader1.Read(Buffer, 0, 2)
            Dim BMPsig As String
            BMPsig = Text.Encoding.Default.GetString(Buffer)

            Select Case BMPsig
                Case "BM"
                    ftext = ftext + "Windows Bitmap" + vbNewLine + vbNewLine + BMPView(FilePath, 14)
                Case "BA"
                    ftext = ftext + "OS/2 Bitmap Array" + vbNewLine + vbNewLine + BAView(FilePath)
                Case = "CI"
                    ftext = ftext + "OS/2 Color Icon" + vbNewLine + vbNewLine + CIView(FilePath, 14 + lOffset) + vbNewLine
                Case = "CP"
                    ftext = ftext + "OS/2 Color Pointer" + vbNewLine + vbNewLine
                Case = "IC"
                    ftext = ftext + "OS/2 Icon" + vbNewLine + vbNewLine
                Case "PT"
                    ftext = ftext + "OS/2 Pointer" + vbNewLine + vbNewLine
                Case Else
                    ftext = ftext + "no Bitmap!"
            End Select
            reader1.BaseStream.Position = Os2BmpArrayHeader.OffsetToNext + 2
            lOffset = CInt(Os2BmpArrayHeader.OffsetToNext)

        Loop Until Os2BmpArrayHeader.OffsetToNext = 0

        BAView = ftext

    End Function

    Public Function GetBMPHeader(isOS2 As Integer, offset As Integer) As String
        Dim offset3 As Integer = 8

        Try
            Dim HeaderSize As UInteger
            If isOS2 = 0 Then
                BitmapFileHeader.Size = reader1.ReadUInt32
                BitmapFileHeader.Reserved = reader1.ReadUInt32
                BitmapFileHeader.BitsOffset = reader1.ReadUInt32
                BitmapInfoHeader.HeaderSize = reader1.ReadUInt32
                HeaderSize = BitmapInfoHeader.HeaderSize
            ElseIf isOS2 = 1 Then
                Os2BmpFileHeader.FileSize = reader1.ReadUInt32
                Os2BmpFileHeader.XHotSpot = reader1.ReadUInt16
                Os2BmpFileHeader.YHotSpot = reader1.ReadUInt16
                Os2BmpFileHeader.BitmapOffset = reader1.ReadUInt32
                Os2_2xBitmapHeader.HeaderSize = reader1.ReadUInt32
                HeaderSize = Os2_2xBitmapHeader.HeaderSize
            End If
            Select Case HeaderSize
                Case 40, 108, 124
                    BitmapInfoHeader.Width = reader1.ReadInt32
                    BitmapInfoHeader.Height = reader1.ReadInt32
                    BitmapInfoHeader.Planes = reader1.ReadUInt16
                    BitmapInfoHeader.BitCount = reader1.ReadUInt16
                    BitmapInfoHeader.Compression = reader1.ReadUInt32
                    BitmapInfoHeader.SizeImage = reader1.ReadUInt32
                    BitmapInfoHeader.PelsPerMeterX = reader1.ReadInt32
                    BitmapInfoHeader.PelsPerMeterY = reader1.ReadInt32
                    BitmapInfoHeader.ClrUsed = reader1.ReadUInt32
                    BitmapInfoHeader.ClrImportant = reader1.ReadUInt32
                    BMPtype = 0
                    If BitmapInfoHeader.HeaderSize = 108 Or BitmapInfoHeader.HeaderSize = 124 Then
                        Bitmap_V4Header.bV4RedMask = reader1.ReadUInt32
                        Bitmap_V4Header.bV4GreenMask = reader1.ReadUInt32
                        Bitmap_V4Header.bV4BlueMask = reader1.ReadUInt32
                        Bitmap_V4Header.bV4AlphaMask = reader1.ReadUInt32
                        Bitmap_V4Header.bV4CSType = reader1.ReadUInt32
                        Bitmap_V4Header.bV4RedX = reader1.ReadInt32
                        Bitmap_V4Header.bV4RedY = reader1.ReadInt32
                        Bitmap_V4Header.bV4RedZ = reader1.ReadInt32
                        Bitmap_V4Header.bV4GreenX = reader1.ReadInt32
                        Bitmap_V4Header.bV4GreenY = reader1.ReadInt32
                        Bitmap_V4Header.bV4GreenZ = reader1.ReadInt32
                        Bitmap_V4Header.bV4BlueX = reader1.ReadInt32
                        Bitmap_V4Header.bV4BlueY = reader1.ReadInt32
                        Bitmap_V4Header.bV4BlueZ = reader1.ReadInt32
                        Bitmap_V4Header.bV4GammaRed = reader1.ReadUInt32
                        Bitmap_V4Header.bV4GammaGreen = reader1.ReadUInt32
                        Bitmap_V4Header.bV4GammaBlue = reader1.ReadUInt32
                        BMPtype = 2
                    End If
                    If BitmapInfoHeader.HeaderSize = 124 Then
                        Bitmap_V5Header.bV5Intent = reader1.ReadUInt32
                        Bitmap_V5Header.bV5ProfileData = reader1.ReadUInt32
                        Bitmap_V5Header.bV5ProfileSize = reader1.ReadUInt32
                        Bitmap_V5Header.bV5Reserved = reader1.ReadUInt32
                        BMPtype = 3
                    End If
                Case 12
                    BitmapCoreHeader.Width = reader1.ReadUInt16
                    BitmapCoreHeader.Height = reader1.ReadUInt16
                    BitmapCoreHeader.Planes = reader1.ReadInt16
                    BitmapCoreHeader.BitCount = reader1.ReadInt16
                    BMPtype = 1
                    offset3 = 6
                Case 64
                    Os2_2xBitmapHeader.Width = reader1.ReadUInt32
                    Os2_2xBitmapHeader.Height = reader1.ReadUInt32
                    Os2_2xBitmapHeader.Planes = reader1.ReadUInt16
                    Os2_2xBitmapHeader.BitCount = reader1.ReadUInt16
                    Os2_2xBitmapHeader.Compression = reader1.ReadUInt32
                    Os2_2xBitmapHeader.ImageDataSize = reader1.ReadUInt32
                    Os2_2xBitmapHeader.XResolution = reader1.ReadUInt32
                    Os2_2xBitmapHeader.YResolution = reader1.ReadUInt32
                    Os2_2xBitmapHeader.ColorsUsed = reader1.ReadUInt32
                    Os2_2xBitmapHeader.ColorsImportant = reader1.ReadUInt32
                    Os2_2xBitmapHeader.Units = reader1.ReadUInt16
                    Os2_2xBitmapHeader.Reserved = reader1.ReadUInt16
                    Os2_2xBitmapHeader.Recording = reader1.ReadUInt16
                    Os2_2xBitmapHeader.Rendering = reader1.ReadUInt16
                    Os2_2xBitmapHeader.Size1 = reader1.ReadUInt32
                    Os2_2xBitmapHeader.Size2 = reader1.ReadUInt32
                    Os2_2xBitmapHeader.ColorEncoding = reader1.ReadUInt32
                    Os2_2xBitmapHeader.Identifier = reader1.ReadUInt16
                    BMPtype = 4
                Case Else
                    GetBMPHeader = "Invalid Header Size! (" + BitmapInfoHeader.HeaderSize.ToString + ")"
                    isError = True
                    Exit Function
            End Select
        Catch
            GetBMPHeader = "no Bitmap!"
            If isOS2 = 1 Then
                GetBMPHeader = "no Color Icon!"
            End If
            isError = True
            Exit Function
        End Try

        Dim ftext As String = ""
        If isOS2 = 0 Then
            ftext = "File Size        : " + BitmapFileHeader.Size.ToString
            ftext = ftext + vbNewLine + "Bits Offset      : " + BitmapFileHeader.BitsOffset.ToString + " (&H" + Hex(BitmapFileHeader.BitsOffset) + ")"
            ftext = ftext + vbNewLine + "Header Size      : " + BitmapInfoHeader.HeaderSize.ToString
        ElseIf isOS2 = 1 Then
            ftext = "File Size        : " + Os2BmpFileHeader.FileSize.ToString
            ftext = ftext + vbNewLine + "X HotSpot        : " + Os2BmpFileHeader.XHotSpot.ToString + " (&H" + Hex(Os2BmpFileHeader.XHotSpot) + ")"
            ftext = ftext + vbNewLine + "Y HotSpot        : " + Os2BmpFileHeader.YHotSpot.ToString + " (&H" + Hex(Os2BmpFileHeader.YHotSpot) + ")"
            ftext = ftext + vbNewLine + "Bits Offset      : " + Os2BmpFileHeader.BitmapOffset.ToString + " (&H" + Hex(Os2BmpFileHeader.BitmapOffset) + ")"
            ftext = ftext + vbNewLine + "Header Size      : " + Os2_2xBitmapHeader.HeaderSize.ToString
        End If

        Dim ttext As String
        Dim HeaderSize2 As UInteger
        If isOS2 = 0 Then
            HeaderSize2 = BitmapInfoHeader.HeaderSize
        ElseIf isOS2 = 1 Then
            HeaderSize2 = Os2_2xBitmapHeader.HeaderSize
        End If

        Select Case HeaderSize2
            Case 12
                ttext = "BITMAPCOREHEADER or OS21XBITMAPHEADER"
            Case 64
                ttext = "OS22XBITMAPHEADER"
            Case 40
                ttext = "BITMAPINFOHEADER"
            Case 56
                ttext = "BITMAPV3INFOHEADER"
            Case 108
                ttext = "BITMAPV4HEADER"
            Case 124
                ttext = "BITMAPV5HEADER"
            Case Else
                GetBMPHeader = "Invalid Header Size!"
                isError = True
                Exit Function
        End Select

        ftext = ftext + " (" + ttext + ")"

        ColorCount = 0
        If BMPtype = 0 Or BMPtype = 2 Or BMPtype = 3 Then
            ftext = ftext + vbNewLine + "Bitmap Size      : " + BitmapInfoHeader.Width.ToString + " x " + BitmapInfoHeader.Height.ToString
            ftext = ftext + vbNewLine + "Planes           : " + BitmapInfoHeader.Planes.ToString
            Select Case BitmapInfoHeader.BitCount
                Case 1
                    ttext = "Mono"
                    ColorCount = 2
                Case 4
                    ttext = "16"
                    ColorCount = 16
                Case 8
                    ttext = "256"
                    ColorCount = 256
                Case 16
                    ttext = "16-bit"
                Case 24
                    ttext = "24-bit"
                Case 32
                    ttext = "32-bit"
                Case Else
                    ttext = "BitCount (" + BitmapInfoHeader.BitCount.ToString + ")"
                    If BitmapInfoHeader.ClrUsed > 0 Then ColorCount = BitmapInfoHeader.ClrUsed
            End Select

            ftext = ftext + vbNewLine + "Color Palette    : " + ttext
            If BitmapInfoHeader.ClrUsed > 0 Then
                ftext = ftext + vbNewLine + "Colors Used      : " + BitmapInfoHeader.ClrUsed.ToString
            End If
            ttext = "all"
            If BitmapInfoHeader.ClrImportant > 0 Then
                ttext = BitmapInfoHeader.ClrImportant.ToString
            End If
            ftext = ftext + vbNewLine + "Colors Important : " + ttext
            Select Case BitmapInfoHeader.Compression
                Case 0
                    ttext = "none"
                Case 1
                    ttext = "RLE 8-bit"
                Case 2
                    ttext = "RLE 4-bit"
                Case 3
                    ttext = "Bitfields"
                Case 4
                    ttext = "RLE 24-bit"
                Case 5
                    ttext = "BI_PNG"
                Case 6
                    ttext = "RGBA Bitfields"
            End Select
            ftext = ftext + vbNewLine + "Compression      : " + ttext
            ftext = ftext + vbNewLine + "Image Size       : " + BitmapInfoHeader.SizeImage.ToString
            ftext = ftext + vbNewLine + "Horizontal Pixels: " + BitmapInfoHeader.PelsPerMeterX.ToString
            ftext = ftext + vbNewLine + "Vertical Pixels  : " + BitmapInfoHeader.PelsPerMeterY.ToString
            If BMPtype = 2 Or BMPtype = 3 Then
                ftext = ftext + vbNewLine + "Red Mask         : " + Bitmap_V4Header.bV4RedMask.ToString
                ftext = ftext + vbNewLine + "Green Mask       : " + Bitmap_V4Header.bV4GreenMask.ToString
                ftext = ftext + vbNewLine + "Blue Mask        : " + Bitmap_V4Header.bV4BlueMask.ToString
                ftext = ftext + vbNewLine + "Alpha Mask       : " + Bitmap_V4Header.bV4AlphaMask.ToString
                ftext = ftext + vbNewLine + "Color Space Type : " + Bitmap_V4Header.bV4CSType.ToString
                ftext = ftext + vbNewLine + "Red Endpoint X   : " + Bitmap_V4Header.bV4RedX.ToString
                ftext = ftext + vbNewLine + "Red Endpoint Y   : " + Bitmap_V4Header.bV4RedY.ToString
                ftext = ftext + vbNewLine + "Red Endpoint Z   : " + Bitmap_V4Header.bV4RedZ.ToString
                ftext = ftext + vbNewLine + "Green Endpoint X : " + Bitmap_V4Header.bV4GreenX.ToString
                ftext = ftext + vbNewLine + "Green Endpoint Y : " + Bitmap_V4Header.bV4GreenY.ToString
                ftext = ftext + vbNewLine + "Green Endpoint Z : " + Bitmap_V4Header.bV4GreenZ.ToString
                ftext = ftext + vbNewLine + "Blue Endpoint X  : " + Bitmap_V4Header.bV4GreenX.ToString
                ftext = ftext + vbNewLine + "Blue Endpoint Y  : " + Bitmap_V4Header.bV4GreenY.ToString
                ftext = ftext + vbNewLine + "Blue Endpoint Z  : " + Bitmap_V4Header.bV4GreenZ.ToString
                ftext = ftext + vbNewLine + "Gamma Red        : " + Bitmap_V4Header.bV4GammaRed.ToString
                ftext = ftext + vbNewLine + "Gamma Green      : " + Bitmap_V4Header.bV4GammaGreen.ToString
                ftext = ftext + vbNewLine + "Gamma Blue       : " + Bitmap_V4Header.bV4GammaBlue.ToString
            End If
            If BMPtype = 3 Then
                ftext = ftext + vbNewLine + "Intent           : " + Bitmap_V5Header.bV5Intent.ToString
                ftext = ftext + vbNewLine + "Profile Data     : " + Bitmap_V5Header.bV5ProfileData.ToString
                ftext = ftext + vbNewLine + "Profile Size     : " + Bitmap_V5Header.bV5ProfileSize.ToString
            End If
        ElseIf BMPtype = 1 Then
            ftext = ftext + vbNewLine + "Bitmap Size      : " + BitmapCoreHeader.Width.ToString + " x " + BitmapCoreHeader.Height.ToString
            ftext = ftext + vbNewLine + "Planes           : " + BitmapCoreHeader.Planes.ToString
            ttext = "unknown"
            Select Case BitmapCoreHeader.BitCount
                Case 1
                    ttext = "Mono"
                    ColorCount = 2
                Case 4
                    ttext = "16"
                    ColorCount = 16
                Case 8
                    ttext = "256"
                    ColorCount = 256
                Case 16
                    ttext = "16-bit"
                Case 24
                    ttext = "24-bit"
                Case 32
                    ttext = "32-bit"
            End Select
            ftext = ftext + vbNewLine + "Color Palette    : " + ttext
        ElseIf BMPtype = 4 Then
            ftext = ftext + vbNewLine + "Bitmap Size      : " + Os2_2xBitmapHeader.Width.ToString + " x " + Os2_2xBitmapHeader.Height.ToString
            ftext = ftext + vbNewLine + "Planes           : " + Os2_2xBitmapHeader.Planes.ToString
            ttext = "unknown"
            Select Case Os2_2xBitmapHeader.BitCount
                Case 1
                    ttext = "Mono"
                    ColorCount = 2
                Case 4
                    ttext = "16"
                    ColorCount = 16
                Case 8
                    ttext = "256"
                    ColorCount = 256
                Case 16
                    ttext = "16-bit"
                Case 24
                    ttext = "24-bit"
                Case 32
                    ttext = "32-bit"
            End Select
            ftext = ftext + vbNewLine + "Color Palette    : " + ttext
            ftext = ftext + vbNewLine + "Compression      : " + Os2_2xBitmapHeader.Compression.ToString
            ftext = ftext + vbNewLine + "Image Data Size  : " + Os2_2xBitmapHeader.ImageDataSize.ToString
            ftext = ftext + vbNewLine + "X Resolution     : " + Os2_2xBitmapHeader.XResolution.ToString
            ftext = ftext + vbNewLine + "Y Resolution     : " + Os2_2xBitmapHeader.YResolution.ToString
            ftext = ftext + vbNewLine + "Colors Used      : " + Os2_2xBitmapHeader.ColorsUsed.ToString
            ftext = ftext + vbNewLine + "Colors Important : " + Os2_2xBitmapHeader.ColorsImportant.ToString
            ftext = ftext + vbNewLine + "Units            : " + Os2_2xBitmapHeader.Units.ToString
            ftext = ftext + vbNewLine + "Reserved         : " + Os2_2xBitmapHeader.Reserved.ToString
            ftext = ftext + vbNewLine + "Recording        : " + Os2_2xBitmapHeader.Recording.ToString
            ftext = ftext + vbNewLine + "Rendering        : " + Os2_2xBitmapHeader.Rendering.ToString
            ftext = ftext + vbNewLine + "Size1            : " + Os2_2xBitmapHeader.Size1.ToString
            ftext = ftext + vbNewLine + "Size2            : " + Os2_2xBitmapHeader.Size2.ToString
            ftext = ftext + vbNewLine + "ColorEncoding    : " + Os2_2xBitmapHeader.ColorEncoding.ToString
            ftext = ftext + vbNewLine + "Identifier       : " + Os2_2xBitmapHeader.Identifier.ToString
        End If

        If isOS2 = 0 Then
            ColorOffset = CInt(14 + BitmapInfoHeader.HeaderSize) + offset
            If BitmapInfoHeader.Compression = 3 Then
                ColorOffset = ColorOffset + 12
            End If
        ElseIf isOS2 = 1 Then
            If ColorOffset > 0 Then
                ColorOffset = CInt(14 + Os2_2xBitmapHeader.HeaderSize) + ColorOffset + offset + offset3
            Else
                ColorOffset = CInt(14 + Os2_2xBitmapHeader.HeaderSize) + offset
            End If
            If Os2_2xBitmapHeader.Compression = 3 Then
                ColorOffset = ColorOffset + 12
            End If
        End If
        ftext = ftext + vbNewLine + vbNewLine + "Color Offset     : " + ColorOffset.ToString + " (&H" + Hex(ColorOffset) + ")" + vbNewLine

        If ColorCount > 0 Then
            reader1.BaseStream.Position = ColorOffset
            Form1.ExColors = ColorCount
            If isOS2 = 0 Then
                If BitmapInfoHeader.ClrUsed > 0 Then
                    Form1.ExColors = BitmapInfoHeader.ClrUsed
                End If
            ElseIf isOS2 = 1 Then
                If Os2_2xBitmapHeader.ColorsUsed > 0 Then
                    Form1.ExColors = Os2_2xBitmapHeader.ColorsUsed
                End If
            End If
            Form1.ToolStripMenuItem7.Enabled = True
            If Form1.ExColors > 256 Then
                Form1.ExColors = 256
            End If

            For i = 1 To Form1.ExColors
                Dim ctext As String
                If BMPtype <> 1 Then
                    Dim RGB_Quad As TagRGBQUAD
                    RGB_Quad.rgbBlue = reader1.ReadByte
                    RGB_Quad.rgbGreen = reader1.ReadByte
                    RGB_Quad.rgbRed = reader1.ReadByte
                    RGB_Quad.rgbReserved = reader1.ReadByte
                    ctext = Space(3 - Len(RGB_Quad.rgbBlue.ToString)) + RGB_Quad.rgbBlue.ToString
                    ctext = ctext + "  " + Space(3 - Len(RGB_Quad.rgbGreen.ToString)) + RGB_Quad.rgbGreen.ToString
                    ctext = ctext + "  " + Space(3 - Len(RGB_Quad.rgbRed.ToString)) + RGB_Quad.rgbRed.ToString
                    Form1.rgb(0, CInt(i - 1)) = RGB_Quad.rgbBlue
                    Form1.rgb(1, CInt(i - 1)) = RGB_Quad.rgbGreen
                    Form1.rgb(2, CInt(i - 1)) = RGB_Quad.rgbRed
                    ftext = ftext + ctext + vbNewLine
                Else
                    Dim RGB_Triple As TagRGBTRIPLE
                    RGB_Triple.rgbtBlue = reader1.ReadByte
                    RGB_Triple.rgbtGreen = reader1.ReadByte
                    RGB_Triple.rgbtRed = reader1.ReadByte
                    ctext = Space(3 - Len(RGB_Triple.rgbtBlue.ToString)) + RGB_Triple.rgbtBlue.ToString
                    ctext = ctext + "  " + Space(3 - Len(RGB_Triple.rgbtGreen.ToString)) + RGB_Triple.rgbtGreen.ToString
                    ctext = ctext + "  " + Space(3 - Len(RGB_Triple.rgbtRed.ToString)) + RGB_Triple.rgbtRed.ToString
                    Form1.rgb(0, CInt(i - 1)) = RGB_Triple.rgbtBlue
                    Form1.rgb(1, CInt(i - 1)) = RGB_Triple.rgbtGreen
                    Form1.rgb(2, CInt(i - 1)) = RGB_Triple.rgbtRed
                    ftext = ftext + ctext + vbNewLine
                End If
            Next i
        End If

        GetBMPHeader = ftext

    End Function
End Module



      Copyright 2021 PeatSoft