Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Drawing.Imaging
- Imports System.Runtime.InteropServices
- Imports System.Runtime.CompilerServices
- 'Author : ibennz
- 'Credits : ibennz
- 'Version : 2
- 'If you use this , please credit me ! <3
- Module Converter
- <Extension()> _
- Public Function ToBitmap(ByVal data As Byte(), Optional ByVal Alpha As Integer = 255, Optional ByVal green As Integer = 100, _
- Optional ByVal red As Integer = 100) As Bitmap
- Dim mSB() As Byte = data
- Dim mImage As Bitmap = New Bitmap(500, CInt(data.Length / 125) + 1)
- Dim pxf As PixelFormat = PixelFormat.Format32bppArgb
- Dim bmpData As BitmapData = mImage.LockBits(New Rectangle(0, 0, mImage.Width, mImage.Height), ImageLockMode.ReadWrite, pxf)
- Dim cPos As IntPtr = bmpData.Scan0
- Dim xVal As Integer = 0
- For Each mByte As Byte In mSB
- Dim cBytes(3) As Byte
- cBytes(3) = CByte(Alpha)
- cBytes(2) = mByte
- cBytes(1) = CByte(green)
- cBytes(0) = CByte(red)
- Marshal.Copy(cBytes, 0, cPos, 4)
- cPos += 4
- xVal += 1
- Next
- mImage.UnlockBits(bmpData)
- Return mImage
- End Function
- <Extension()> _
- Public Function ToBitmap(ByVal data As String, Optional ByVal Alpha As Integer = 255, Optional ByVal green As Integer = 100, _
- Optional ByVal red As Integer = 100) As Bitmap
- Dim mSB() As Byte = System.Text.Encoding.UTF8.GetBytes(data)
- Dim mImage As Bitmap = New Bitmap(500, CInt(data.Length / 125) + 1)
- Dim pxf As PixelFormat = PixelFormat.Format32bppArgb
- Dim bmpData As BitmapData = mImage.LockBits(New Rectangle(0, 0, mImage.Width, mImage.Height), ImageLockMode.ReadWrite, pxf)
- Dim cPos As IntPtr = bmpData.Scan0
- Dim xVal As Integer = 0
- For Each mByte As Byte In mSB
- Dim cBytes(3) As Byte
- cBytes(3) = CByte(Alpha)
- cBytes(2) = mByte
- cBytes(1) = CByte(green)
- cBytes(0) = CByte(red)
- Marshal.Copy(cBytes, 0, cPos, 4)
- cPos += 4
- xVal += 1
- Next
- mImage.UnlockBits(bmpData)
- Return mImage
- End Function
- <Extension()> _
- Public Function ToBytes(ByVal file As Image) As Byte()
- Dim img As New Bitmap(file)
- Dim mList As New System.Collections.Generic.List(Of Byte)
- Dim pxf As PixelFormat = PixelFormat.Format32bppArgb
- Dim bmpData As BitmapData = img.LockBits(New Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadWrite, pxf)
- Dim mPos As IntPtr = bmpData.Scan0
- Dim mPixels As Integer = (Math.Abs(bmpData.Stride)) * img.Height - 1
- For i As Integer = 0 To mPixels - 1
- Dim currentByte(3) As Byte
- Marshal.Copy(mPos, currentByte, 0, 4)
- If currentByte(3) = 0 And currentByte(2) = 0 And currentByte(1) = 0 And currentByte(0) = 0 Then
- Exit For
- End If
- mList.Add(currentByte(2))
- mPos = New IntPtr(CInt(mPos) + 4)
- Next
- img.UnlockBits(bmpData)
- Return mList.ToArray
- End Function
- <Extension()> _
- Public Function ToString(ByVal file As Image) As String
- Dim img As New Bitmap(file)
- Dim mList As New System.Text.StringBuilder
- Dim pxf As PixelFormat = PixelFormat.Format32bppArgb
- Dim bmpData As BitmapData = img.LockBits(New Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadWrite, pxf)
- Dim mPos As IntPtr = bmpData.Scan0
- Dim mPixels As Integer = (Math.Abs(bmpData.Stride)) * img.Height - 1
- For i As Integer = 0 To mPixels - 1
- Dim currentByte(3) As Byte
- Marshal.Copy(mPos, currentByte, 0, 4)
- If currentByte(3) = 0 And currentByte(2) = 0 And currentByte(1) = 0 And currentByte(0) = 0 Then
- Exit For
- End If
- mList.Append(System.Convert.ToChar(currentByte(2)))
- mPos = New IntPtr(CInt(mPos) + 4)
- Next
- img.UnlockBits(bmpData)
- Return mList.ToString
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment