Solved

save, display images as data streams from DB

Posted on 1999-01-08
1
159 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

8 Experts available now in Live!

Get 1:1 Help Now