Results 1 to 4 of 4

Thread: Loading from memory

  1. #1

    Thread Starter
    New Member nullmind's Avatar
    Join Date
    Nov 2002
    Posts
    3

    Loading from memory

    hey all, Working with a graphics app in VB for the frist time (usually dont use VB).

    Basically, I want to open a file (that contains seperate forms of data, sounds, images etc.) Then, *without* dumping into a temporary file or anything, i want to load an image from it. I know the format very well, so i know where all images and such are. This should be possable right? If not I'm kinda screwed, the other language i develop in can do this, but doesnt off win32 interface.

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Code:
    Dim iFileNum as integer
    Dim sMemBuf as string
    Dim lMemSize as long, lStartPos as long
    
    iFileNum = freefile
    open "myfile.ext" for binary as #ifilenum
    lmemsize = <whatever you set it>
    smembuf = space$(lmemsize)
    lstartpos = <something>
    get #ifilenum, lstartpos, smembuf
    
    close #ifilenum
    Note, in VB file positions are one-based! Not zero-based in languages such as C/C++.
    In this example I'm using a string as a buffer to store data into. It can even hold non-ascii characters and doesn't convert returns to Windows-format.
    Since you know the used file format well, you should be able to determine what the memsize and startpos will be.

  3. #3

    Thread Starter
    New Member nullmind's Avatar
    Join Date
    Nov 2002
    Posts
    3
    w00t. Ok, hehe, ill humor you some more with my lack of VB experience. How could i get this into a picturebox, without saving it..or hell, with saving it if i have too

  4. #4
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Read until you are the offset into the file where the graphic starts.
    Then write the graphic to a file.

    Assuming the graphic is of a type Windows COM controls can use then do
    Code:
    ' with a picture box on the form
    Picture1.LoadPicture "filename"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width