Module ModuleHelper
    Public Function ByteArrayToBitmap(bytearray() As Byte) As Bitmap
        Try
            Dim oBitmap As Bitmap

            Using oStream As New IO.MemoryStream(bytearray)
                oBitmap = New Bitmap(oStream)
            End Using

            Return oBitmap
        Catch ex As Exception
            LOGGER.Error(ex)
            Return Nothing
        End Try
    End Function

    Public Function StringToByteArray(ByVal hex As String) As Byte()
        Dim NumberChars As Integer = hex.Length

        Dim bytes(NumberChars / 2) As Byte

        For i As Integer = 0 To NumberChars - 1 Step 2
            bytes(i / 2) = Convert.ToByte(hex.Substring(i, 2), 16)
        Next

        Return bytes
    End Function

    Public Function BitmapToByteArray(bitmap As Bitmap) As Byte()
        Dim bytearray As Byte()

        Using stream As New System.IO.MemoryStream
            bitmap.Save(stream, bitmap.RawFormat)
            bytearray = stream.ToArray()
        End Using

        Return bytearray
    End Function
End Module
