Public Function imageToByteArray(ByVal imageIn As System.Drawing.Image, ByVal pformato As System.Drawing.Imaging.ImageFormat) As Byte()
Dim ms As New IO.MemoryStreamTry
imageIn.Save(ms, pformato)
Catch ex As Exception
End Try
Return ms.ToArray()
End Function
Dim returnImage As Image = Nothing
Try
Dim ms As New IO.MemoryStream(byteArrayIn)
returnImage = Image.FromStream(ms)
Catch ex As Exception
End Try
Return returnImage
End Function
Private Function ArrayToString(ByVal bytes() As Byte, Optional ByVal format As String = Nothing) As String
If bytes.Length = 0 Then Return String.Empty
Dim sb As New System.Text.StringBuilder(bytes.Length * 4)
For Each b As Byte In bytes
sb.Append(b.ToString(format))
sb.Append(","c)
Next
sb.Length -= 1
Return sb.ToString()
End Function
Private Function StringToArray(ByVal s As String, Optional ByVal style As System.Globalization.NumberStyles = Nothing) As Byte()
If s.Length = 0 Then Return New Byte() {}
Dim values() As String = s.Split(","c)
Dim bytes(values.Length - 1) As Byte
For index As Integer = 0 To values.Length - 1
bytes(index) = Byte.Parse(values(index), style)
Next
Return bytes
End Function
'Ejemplo Imagen a String-->
dim strImage as string=""
strImage = ArrayToString(imageToByteArray(My.Resources.miImagen, System.Drawing.Imaging.ImageFormat.Png), Nothing)
Y el codigo de string a imagen
ResponderEliminar