Solved

save, display images as data streams from DB

Posted on 1999-01-08
1
162 Views
Last Modified: 2010-05-03
What controls/tools/techniques should I use to save, retrieve, and display images that are stored in a data base.  I am working through a Business Layer and Persistent layer that will furnish/accept binary streams of data, but don't know anything specific about bitmap file formats.

I can deal with file based images easily.

Any direction will be helpful.
0
Comment
Question by:tspratt
1 Comment
 
LVL 15

Accepted Solution

by:
ameba earned 100 total points
ID: 1454977
Tools: You can use VB6 and DAO, pictures can be in .MDB file.
Controls: PictureBox or your own UserControl based on PictureBox, with scrollbars.

Good idea is to have file based images, and save only thumbnails to your DB.

------------------
In your Business Layer you will need something like:

Private mThumbnail As Variant

Public Property Let Thumbnail(ByVal NewVal As Variant)
    mThumbnail = NewVal
End Property

Public Property Get Thumbnail() As Variant
    Thumbnail = mThumbnail
End Property

To Retrieve from db to your business object
    ' Transfer the field values to the properties
    With tempRS
        If Not IsNull(!Thumbnail) Then
            Thumbnail = !Thumbnail.GetChunk(0, !Thumbnail.FieldSize)
        Else
            Thumbnail = Null
        End If
    End With

To Save:
    ' Transfer the property values to the recordset
    With tempRS
        If Not IsNull(Thumbnail) Then
            !Thumbnail.AppendChunk Thumbnail
        Else
            !Thumbnail = Null
        End If
    End With

------------------
In your UI layer (form):

Sub ClearControls()
    ' Turn off controls
    picBinThumbnail.Picture = LoadPicture()
End Sub

To UpdateRecord:
    With m_Bus ' business object
        If picBinThumbnail.Image.Height > 0 Then
            Dim tmpThumbnail() As Byte
            Dim tmpfileThumbnail As String
            Dim flenThumbnail As Long
            If GetTempFilenam(tmpfileThumbnail) = True Then
                SavePicture picBinThumbnail.Image, tmpfileThumbnail
                Open tmpfileThumbnail For Binary As #1
                flenThumbnail = LOF(1)
                ReDim tmpThumbnail(flenThumbnail)
                Get #1, , tmpThumbnail
                Close #1
                .Thumbnail = tmpThumbnail
                Erase tmpThumbnail
                Kill tmpfileThumbnail ' DELETE TEMPORARY FILE
            Else
                .Thumbnail = Null
            End If
        Else
            .Thumbnail = Null
        End If
    End With

To show record:
    With m_Bus ' business object
        picBinThumbnail.AutoRedraw = True
        picBinThumbnail.Cls
        Dim tmpThumbnail() As Byte      ' temporary byte array
        Dim tmpfileThumbnail As String  ' temporary file
        If Not IsNull(.Thumbnail) Then
            ReDim tmpThumbnail(Len(.Thumbnail))
            tmpThumbnail = .Thumbnail
            If GetTempFilenam(tmpfileThumbnail) = True Then
                Open tmpfileThumbnail For Binary As #1
                Put #1, , tmpThumbnail
                Close #1
                With picBinThumbnail
                    .PaintPicture LoadPicture(tmpfileThumbnail), 0, 0, .Width, .Height
                    picBinThumbnail.AutoRedraw = False
                End With
                'picBinThumbnail.Picture = LoadPicture(tmpfileThumbnail) ' another method
                Erase tmpThumbnail
                Kill tmpfileThumbnail ' DELETE TEMPORARY FILE
            Else
                picBinThumbnail.Picture = LoadPicture()
            End If
        Else
            picBinThumbnail.Picture = LoadPicture()
        End If
        'picBinThumbnail.AutoSize = True ' optional
    End With

In your UI you will also need CommonDialog and code to open picture file.
------------------
Hope this helps.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 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

18 Experts available now in Live!

Get 1:1 Help Now