Как я могу конвертировать изображение
я не какая то лентяйская ошибка Я не понял
Что я уже пробовал:
Imports System.IO Imports System.Text Public Class Form1 Dim path As String = Directory.GetCurrentDirectory() Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ''First i choose a img to convert to byte Dim img As Image = Image.FromFile("C:\Users\admin\Desktop\1550157567366_1-xlg400x400.jpg") ''Second i convertexd the image to byte Dim bArr As Byte() = imgToByteArray(img) ''third i converted byte to string Dim istring As String = Bytes_To_String2(bArr) 'just exported to a text file in same path folder '---------------------------------- ExportTextFile(istring) ' Dim bArr2 As Byte() = stringToByteArray(istring) '---------------------------------- 'Step four back to back from string to byte Dim bArr2 As Byte() = ToByteArray(istring) 'step five bytes to img last stage is confusion Dim img1 As Image = byteArrayToImage(bArr2) 'dint no see any picture in the picturebox1 PictureBox1.Image = img1 End Sub Public Function imgToByteArray(ByVal img As Image) As Byte() 'Fisrt step Using mStream As New MemoryStream() img.Save(mStream, img.RawFormat) Return mStream.ToArray() End Using End Function Private Function Bytes_To_String2(ByVal bytes_Input As Byte()) As String 'Second Step conversion of byte to sring Dim strTemp As New StringBuilder(bytes_Input.Length * 2) For Each b As Byte In bytes_Input strTemp.Append(Conversion.Hex(b)) Next MsgBox(strTemp.ToString()) Return strTemp.ToString() End Function Sub ExportTextFile(ByVal revokedlinks As String) 'thrid Step Convesion of string to text file Dim RevokedTextFile As String = path & "\StringToTextFile.txt" If File.Exists(RevokedTextFile) = True Then Dim appendText As String = revokedlinks File.AppendAllText(RevokedTextFile, appendText) Dim readText As String = File.ReadAllText(RevokedTextFile) End If If File.Exists(RevokedTextFile) = False Then Dim createText As String = revokedlinks File.WriteAllText(RevokedTextFile, createText) End If End Sub Public Function ToByteArray(ByVal someString As String) As Byte() 'step four Dim byteList As New List(Of Byte) Try Dim tempString As String = someString.Replace("&H", "") If tempString.Length Mod 2 = 1 Then tempString = "0" & tempString For index As Integer = 0 To tempString.Length Step 2 byteList.Add(Convert.ToByte(Val("&H" & tempString.Substring(index, 2)))) Next Catch ex As Exception MessageBox.Show(ex.ToString) End Try Return byteList.ToArray End Function 'convert bytearray to image Public Function byteArrayToImage(ByVal byteArrayIn As Byte()) As Image 'step 5 dint work Using mStream As New MemoryStream(byteArrayIn) Return Image.FromStream(mStream) End Using End Function End Class