Hello. I was looking for how to convert image to byte array, and i found this https://www.vbforums.com/showthread....-on-Picturebox. It works on my case, but i have no idea why is the code like that, what is GUID, and why i must use that. Can i use the identifier randomly? i need an explanation for this code. i've tried to googled it but still can't understand. Here's the code.
Code:Private Function ArrayToPicture(inArray() As Byte, Offset As Long, Size As Long) As IPicture ' function creates a stdPicture from the passed array ' Offset is first item in array: 0 for 0 bound arrays ' Size is how many bytes comprise the image Dim o_hMem As Long Dim o_lpMem As Long Dim aGUID(0 To 3) As Long Dim IIStream As IUnknown aGUID(0) = &H7BF80980 ' GUID for stdPicture aGUID(1) = &H101ABF32 aGUID(2) = &HAA00BB8B aGUID(3) = &HAB0C3000 o_hMem = GlobalAlloc(&H2&, Size) If Not o_hMem = 0& Then o_lpMem = GlobalLock(o_hMem) If Not o_lpMem = 0& Then CopyMemory ByVal o_lpMem, inArray(Offset), Size Call GlobalUnlock(o_hMem) If CreateStreamOnHGlobal(o_hMem, 1&, IIStream) = 0& Then Call OleLoadPicture(ByVal ObjPtr(IIStream), 0&, 0&, aGUID(0), ArrayToPicture) End If End If End If End Function
I use it with this code
Code:Public Function Base64Encode(vArr As Variant) As String Const Routine As String = "Base64.Base64Encode" Dim xmlDoc As Object Dim xmlNode As Object Set xmlDoc = CreateObject("MSXML2.DOMDocument") Set xmlNode = xmlDoc.createElement("b64") xmlNode.DataType = "bin.base64" xmlNode.nodeTypedValue = vArr Base64Encode = xmlNode.Text End Function




Reply With Quote