NTGuru705
asked on
Convert MemoryStream to Byte Array
I need to convert a MemoryStream to a byte array..
Here is my code..
Dim ms As New MemoryStream(ccDocument) 'ccDocument is a byte array
Dim ccReturn As Byte(ms.Length)
ms.Read(ccReturn, 0, ms.Length)
Can anyone tell me if the above code is correct?... yes I know it comes in as a byte converts to stream and then back to byte....
Thanks
Here is my code..
Dim ms As New MemoryStream(ccDocument) 'ccDocument is a byte array
Dim ccReturn As Byte(ms.Length)
ms.Read(ccReturn, 0, ms.Length)
Can anyone tell me if the above code is correct?... yes I know it comes in as a byte converts to stream and then back to byte....
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Imports System.IO
Imports System.Drawing.Imaging
Public Class ImageConverter
Public Shared Function ByteArrayToImage(ByVal buffer() As Byte, ByVal fileName As String) As Image
Using ms As New MemoryStream(buffer)
Dim img As Image = Image.FromStream(ms)
Return img
End Using
End Function
Public Shared Function ImageToByteArray(ByVal img As Image, ByVal format As ImageFormat) As Byte()
Using ms As New MemoryStream()
img.Save(ms, format)
Return ms.ToArray()
End Using
End Function
Public Shared Function ImageToBase64String(ByVal img As Image, ByVal format As ImageFormat) As String
Using ms As New MemoryStream()
img.Save(ms, format)
Return Convert.ToBase64String(ms.
End Using
End Function
Public Shared Function Base64StringToImage(ByVal imageString As String) As Image
Dim buffer() As Byte = Convert.FromBase64String(i
Using ms As New MemoryStream(buffer)
Return Image.FromStream(ms)
End Using
End Function
End Class
Bob