Solved

save, display images as data streams from DB

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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