Binding a Picture object to a Image data type field

Posted on 2004-11-26
Last Modified: 2013-12-25

In a VB6 SQL 2000 application, I use an Image data type field to store .bmp file.

Is there a way to display the bmp file in a Picture object without having to save the file locally?
I know I can save the file somewhere using

    Dim rs         As ADODB.Recordset
    Dim stmDocTest As ADODB.Stream
    Dim strFile    As String

    Set stmDocTest = New ADODB.Stream
    stmDocTest.Type = adTypeBinary
    stmDocTest.Write rsDocument!docInsert
    strFile = App.Path & "\TEMP\"
    stmDocTest.SaveToFile strFile, adSaveCreateOverWrite

I would like to bind directly the Picture object to the Image data field without having to save the file locally
Something like...

   Set Picture1.Picture = rsDocument!docInsert  (wich does work)

 .... without having to save the file locally is my key issue

Thank you

Question by:MarioCantin
    1 Comment
    LVL 7

    Accepted Solution

    The problem is that loading from a file is built in to the picture box control, that is the only way it knows how to do it.
    You can 'trick' it though, just place your picturebox wherever you want it to be.
    Then you will have to use some API calls to modify the hDC (windows device handle to the bitmap displayed), in VB you can not change the hDC property it is read only you can modify the BMP that the hDC points to. Unless you want to go the route of setting pixels manually (your own BMP decode routine NOT recommended) or find a custom Picturebox replacement that will load from a stream then this is the only way I can think of doing this. You may need more robust support you can get the BMP header info for the formats you desire to support by searching for "BMP file structure" and replacing the code in this accordingly. This should get you going.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now