Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

save, display images as data streams from DB

Posted on 1999-01-08
1
Medium Priority
?
184 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 400 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

824 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