Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

save, display images as data streams from DB

Posted on 1999-01-08
1
Medium Priority
?
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
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…
Suggested Courses

721 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