JPERKS1985
asked on
Image to memory stream
I have a function i'm using to generate an md5 off an image
Dim MD5ImageStream As New IO.MemoryStream(ayfile)
ayfile represents "capacity as integer"
I was using Dim ayFile() As Byte = ConnectStreamToByteArray(o Stream)
before. Now I'm using
Dim oImage As Image = Image.FromStream(oStream)
What would I pass to md5imagestream in place of ayfile?
Dim MD5ImageStream As New IO.MemoryStream(ayfile)
ayfile represents "capacity as integer"
I was using Dim ayFile() As Byte = ConnectStreamToByteArray(o
before. Now I'm using
Dim oImage As Image = Image.FromStream(oStream)
What would I pass to md5imagestream in place of ayfile?
ASKER
That doesn't seem to work. Thanks for your help thus far. The stream is created this way
Dim oStream As Stream = oResponse.GetResponseStrea m
I must be able to pass the finished product to
Private Function MD5_Hash(ByVal Fs As Stream) As String
Dim md5 As New MD5CryptoServiceProvider
Dim hash() As Byte
Try
hash = md5.ComputeHash(Fs)
Fs.Close()
md5.Clear()
Return BitConverter.ToString(hash ).Replace( "-", "").ToUpper
Catch ex As Exception
'MsgBox(ex.Message.ToStrin g)
Return Nothing
End Try
Dim oStream As Stream = oResponse.GetResponseStrea
I must be able to pass the finished product to
Private Function MD5_Hash(ByVal Fs As Stream) As String
Dim md5 As New MD5CryptoServiceProvider
Dim hash() As Byte
Try
hash = md5.ComputeHash(Fs)
Fs.Close()
md5.Clear()
Return BitConverter.ToString(hash
Catch ex As Exception
'MsgBox(ex.Message.ToStrin
Return Nothing
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry I'm starying to confuse myself,
I used to use
Private Function ConnectStreamToByteArray(B yVal poStream As Stream) As Byte()
Dim obj45 As Object = New Object
SyncLock obj45
Dim ayRet() As Byte
Dim icnt As Integer
Try
Do
ReDim Preserve ayRet(icnt)
'* Read the Byte into the array
ayRet(icnt) = poStream.ReadByte
'* Increment
icnt = (icnt + 1)
Loop
Catch ex As Exception
'* Do nothing. The Stream is Completed
End Try
'* Return the Byte Array
Return ayRet
End SyncLock
End Function
To convert ostream into the proper format, however that was slowing down the thread. Now I need an alternative to either use ostream to convert to the proper formatfrom either oimage or ostream or even a modficatio to the hash function so I can pass the oimage directly.
I used to use
Private Function ConnectStreamToByteArray(B
Dim obj45 As Object = New Object
SyncLock obj45
Dim ayRet() As Byte
Dim icnt As Integer
Try
Do
ReDim Preserve ayRet(icnt)
'* Read the Byte into the array
ayRet(icnt) = poStream.ReadByte
'* Increment
icnt = (icnt + 1)
Loop
Catch ex As Exception
'* Do nothing. The Stream is Completed
End Try
'* Return the Byte Array
Return ayRet
End SyncLock
End Function
To convert ostream into the proper format, however that was slowing down the thread. Now I need an alternative to either use ostream to convert to the proper formatfrom either oimage or ostream or even a modficatio to the hash function so I can pass the oimage directly.
What happens when you try the following (I'm assuming that you already have oImage as an Image - and you might need to change the image format to the appropriate format):
Dim MD5ImageStream As New IO.MemoryStream
oImage.Save(MD5ImageStream , System.Drawing.Imaging.Ima geFormat.B mp)
Dim hash As String = MD5_Hash(MD5ImageStream)
Messagebox.show(hash)
Dim MD5ImageStream As New IO.MemoryStream
oImage.Save(MD5ImageStream
Dim hash As String = MD5_Hash(MD5ImageStream)
Messagebox.show(hash)
ASKER
You got it man , I get a good hash (thats not the default blank hash). Thanks for the help id buy you a drink if we wern't online. haha
lol - no worries! buy it anyway and drink it for me :)
try something like this (from: http://www.dotnet247.com/247reference/msgs/22/112124.aspx):
Dim myImage As Image
Dim ms As New IO.MemoryStream
myImage.Save(ms, System.Drawing.Imaging.Ima
Dim b(ms.Length - 1) As Byte
ms.Position = 0
ms.Read(b, 0, ms.Length)
Cheers,
Hillwaaa