Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Can we view a picture from its memory data?

36 views
Skip to first unread message

Karl E. Peterson

unread,
Dec 7, 2005, 4:45:03 PM12/7/05
to
Andrew wrote:
> Hello, friends,
>
> In our VB6 app, we loaded .jpg files into memory. After certain
> processing, we save all data into a .jpg file and use an Image
> control to view the processed pictures.
>
> Is there a way that we can pass those memory .jpg data into Image
> control, or any other controls, so that we can view the processed
> pictures without saving into a .jpg file?
>
> Any suggestions, ideas, reference papers, sample source code, etc.?

Yeah, I think so. I have a similar situation, where I download JPG images
from the web, and have them stored in byte arrays. Not sure if that (a byte
array that holds the file image of a JPG) is exactly what you got, though?
If so, you'll need to dig up a copy of Edanmo's OLELIB typelib, and then use
code like this...

' ********************************************************************
' This function was taken from Edanmo's site:
' http://www.mvps.org/emorcillo/vb6/multimedia/picturefromarray.shtml
' and requires a reference to OLELIB.TLB to work
' --------------------------------------------------------------------
' Load a picture from a byte array
' If you want to load a picture (other than BMP) from a resource or
' a database without saving it to disk you can use this function.
' The function loads the array in a memory stream and then uses the
' IPersistStream of the StdPicture object to loads the image from
' the stream.
' Example:
' Me.Picture = LoadImage(LoadResData(101, "Custom"))
' ********************************************************************
Private Function LoadImage(ImageBytes() As Byte) As StdPicture
Dim oPersist As IPersistStream
Dim oStream As IStream
Dim lSize As Long

' Calculate the array size
lSize = UBound(ImageBytes) - LBound(ImageBytes) + 1

' Create a stream object
' in global memory
Set oStream = CreateStreamOnHGlobal(0, True)

' Write the header to the stream
oStream.Write &H746C&, 4&

' Write the array size
oStream.Write lSize, 4&

' Write the image data
oStream.Write ImageBytes(LBound(ImageBytes)), lSize

' Move the stream position to
' the start of the stream
oStream.Seek 0, STREAM_SEEK_SET

' Create a new empty picture object
Set LoadImage = New StdPicture

' Get the IPersistStream interface
' of the picture object
Set oPersist = LoadImage

' Load the picture from the stream
oPersist.Load oStream

' Release the streamobject
Set oStream = Nothing
End Function
' ********************************************************************

Later... Karl
--
Working without a .NET?
http://classicvb.org/


0 new messages