81 lines
2.2 KiB
VB.net
81 lines
2.2 KiB
VB.net
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
|
|
|
|
''' <summary>
|
|
''' Versucht einen String in einen Boolean zu konvertieren
|
|
''' </summary>
|
|
''' <param name="str">Der zu konvertierende String</param>
|
|
''' <returns>Den umgewandelten Wert oder False</returns>
|
|
Public Function StrToBool(str As String) As Boolean
|
|
Dim result As Boolean = False
|
|
|
|
Try
|
|
result = Convert.ToBoolean(str)
|
|
Catch ex As Exception
|
|
LOGGER.Error(ex)
|
|
result = False
|
|
End Try
|
|
|
|
Return result
|
|
End Function
|
|
|
|
''' <summary>
|
|
''' Konvertiert eine Zahl in die entsprechende Farbe
|
|
''' </summary>
|
|
Public Function IntToColor(int As Integer) As Color
|
|
Return ColorTranslator.FromWin32(int)
|
|
End Function
|
|
|
|
Public Function PrepareLogMessage(LogMessage As String) As String
|
|
Dim oLogSplit As String()
|
|
oLogSplit = LogMessage.Split("|")
|
|
|
|
If oLogSplit.Count < 3 Then
|
|
Return LogMessage
|
|
Else
|
|
Dim omsg = oLogSplit(2).
|
|
Replace("'", "''").
|
|
Replace("\\n", "").
|
|
Replace(Chr(13), "").
|
|
Replace(Chr(10), "")
|
|
Return omsg
|
|
End If
|
|
End Function
|
|
End Module
|