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



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/


.



Relevant Pages

  • Re: view menu
    ... > The jpg file contains the compressed picture. ... > i.e. the stored image isn't exactly the picture you created but looks ... This way it can be stored using little memory. ...
    (comp.graphics.apps.gimp)
  • Memory Full (C.R.5)
    ... Why when I try to insert a picture (.jpg file) using the Insert/Picture ... MEMORY FULL ...
    (microsoft.public.vb.crystal)
  • Re: Display stored JPGs on a form
    ... I create a form with a Bound Object Frame control that has as its control ... the JPG file type and change it from Internet Exploer to MS Office Picture ...
    (microsoft.public.access.forms)
  • Re: Creating a Logo with PowerPoint (or Publisher)
    ... the picture as a .jpg file. ... opt to save as PNG. ... be less expensive in the long run to send someone a PNG or even the PPT ... provide you with EPS, PNG, GIF, and probably also a JPG file. ...
    (microsoft.public.powerpoint)
  • Re: windows Picture & Fax viewer error
    ... > When I double click an attached jpg file in outlook, ... > enough memory to open the file". ... The jpg file is only 2MB. ... also easily be that windows picture & fax viewer has no such problem. ...
    (microsoft.public.windowsxp.general)