Private Shared Function ConvertImages(ByVal ds As DataSet) As DataSet
'ds.Tables("tDetail").Columns.Add("IMG", System.Type.GetType("System.Byte[]"))
Dim convert As New bll.functions.PrefStreamConverter
For Each row As DataRow In ds.Tables("tDetail").Rows
row("IMG") = convert.GetBinaryStream(row("imgxml"), 200, 200) 'o.GetDecoded 'Convert.FromBase64String(Convert.ToBase64String(row("Thumbnail")))
Next
ds.AcceptChanges()
Return ds
End Function
Imports Interop.PrefView
Imports System.IO
Namespace bll.functions
Public Class PrefStreamConverter
Public Function GetMemStream(ByVal xml As String, ByVal width As Integer, ByVal height As Integer) As MemoryStream
Dim ret As MemoryStream
Dim PrefRend As New PrefModelRenderer
PrefRend.SetXMLDraw(xml)
Dim PrefStream As IStream = PrefRend.GetBitmap(width, height)
ret = IStreamToMemoryStream(PrefStream)
Return ret
End Function
Public Function GetBinaryStream(ByVal xml As String, ByVal width As Integer, ByVal height As Integer) As Byte()
Dim ms As MemoryStream = GetMemStream(xml, width, height)
Dim len As Integer = ms.Length
Dim b() As Byte
b = ms.ToArray()
ms.Close()
Return b
End Function
'''
''' convert the IStream into a MemoryStream
'''
'''
'''
'''
Private Function IStreamToMemoryStream(ByVal iStream As IStream) As MemoryStream
Dim iBufferSize As Long
Dim byteVector() As Byte
Dim nSeek As _LARGE_INTEGER
Dim nullLarge As _ULARGE_INTEGER
Dim iBytesReaded As ULong = 1
If IStream Is Nothing Then
Return Nothing
End If
Dim memoryStream As MemoryStream = New MemoryStream()
Dim binaryWriter As BinaryWriter = New BinaryWriter(memoryStream)
'Init Variables
iBufferSize = 2048
nSeek.QuadPart = 0
'Seek the Stream to the begin
IStream.RemoteSeek(nSeek, 0, nullLarge)
Do While iBytesReaded > 0
'Reads the Bytes
ReDim byteVector(2048) 'byteVector = new Byte [2048];
'Read Bytes
IStream.RemoteRead(byteVector(0), CType(iBufferSize, ULong), iBytesReaded)
'And write it to the MemoryStream
binaryWriter.Write(byteVector, 0, CType(iBytesReaded, Long))
binaryWriter.Flush()
Loop
memoryStream.Position = 0
Return memoryStream
End Function
End Class
End Namespace
|