?
Solved

Store/view a scanned document?

Posted on 2000-01-27
15
Medium Priority
?
437 Views
Last Modified: 2010-05-02
What might be the best way to store and view a scanned document with Visual Basic?  I have a SQL 7.0 server, so I suppose I could store it in a binary field in a table - or would it be better to just have a pointer to a file on disc?  How to actually get it in there?  How about viewing the document on screen?

Multiple questions deserves extra points - setting this one to 400.

Kelly
0
Comment
Question by:kbakst
  • 6
  • 4
  • 2
  • +2
15 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 2395091
UI suggestion:
Listview on the left side, usercontrol (or picturebox with scrollbars) on the right side.
See MS Exchange 'Fax Viewer' for ideas.

Listview is with thumbnails (e.g. size 54 x 71 pixels).
thumbnails are saved to DB as binary type, real bitmaps are on disk.
When form loads you can load 100 or more thumbnails to listview without any problem. When user clicks on thumbnail, i.e. icon in your listview, you load real bitmap from disk and show it.
It is also good idea to have categories for your documents and organize folders. You'll need second DB table for this.
(IOW, don't keep 20000 pictures in one single folder :)
0
 
LVL 1

Expert Comment

by:sdland1
ID: 2395097
I think i saw an example like this at http://lightning.prohosting.com/~shell123 if i remember right it was in the sniplets section or could have been in the full applications section
0
 
LVL 15

Expert Comment

by:ameba
ID: 2395385
spam
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 14

Expert Comment

by:mcrider
ID: 2395546
ameba, spam?  What are you talking about?


Cheers!
0
 

Author Comment

by:kbakst
ID: 2395561
For ameba - so I should store the actual pictures on disc?  Why is this better than storing it in the DB?  What is the advantage of a usercontrol over a picturebox?  Are there good 3rd party controls for viewing pictures that I should consider?
0
 

Author Comment

by:kbakst
ID: 2395564
sdland1 posted spam as a comment.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2395597
Oh I get it... sdland1 profile: "Senior VB developer For LandSoft Ent" and the weblink is to his site... Self promotion, but maybe not spam... I took a look at the VB code library there and there do seem to be alot of items there.

But, I didn't see anything specific about this question...

Back to this question, alot of experts here agree that storing images in databases is not a good idea.  Storing the pointers in a database and actually loading the image from a file on disk is supposed to be faster...


Cheers!
0
 
LVL 15

Expert Comment

by:ameba
ID: 2396283
>LandSoft
Mentioning your own product or site is *OK* if it directly  solves the problem. If it says - go through/search sections and you will MAYBE find something, then it is spam.

I think it is OK to have some promotion for top experts who contributed a lot to this community. But this is not the case.
0
 
LVL 15

Expert Comment

by:ameba
ID: 2396334
kbakst
>so I should store the actual pictures on disc?
Yes. Store only filename in your DB

>Why is this better than storing it in the DB?
Faster access. File System is the best database for storing files. Easier backup, easier admin work, easier storing on multiple servers...

>What is the advantage of a usercontrol over a picturebox?
Hidden code complexity. But picturebox will also work:
http://www.vb-helper.com/HowTo/scrwin.zip

>Are there good 3rd party controls for viewing pictures that I should consider?
I think it is better to create your own, so you will have its source.
0
 
LVL 3

Expert Comment

by:KhollAD
ID: 2397784
You can use the code below to Read and Write Images in DB :

-- Add the Remote Data Objects Reference to your project (this code uses RDO, But you can change the code to use ADO also.)
-- Run the script in your DB to create the test table :

CREATE TABLE dbo.ImgTable (
      Img_ID int NOT NULL ,
      Img_Description varchar (40) NULL ,
      Img_Bitmap image NULL
)

-- Picture1 is your scanned image.

Dim en As rdoEnvironment
Dim Cn As rdoConnection
Dim Rs As rdoResultset

Dim sql As String

Dim Fl As Long, Chunks As Integer
Dim Fragment As Integer, Chunk() As Byte, I As Integer

Const ChunkSize As Integer = 16384

Private Sub Form_Load()

Set en = rdoEnvironments(0)

Set Cn = en.OpenConnection(dsName:="", _
    Prompt:=rdDriverNoPrompt, _
    Connect:="uid=sa;pwd=;driver={SQL Server};" _
        & "server=YOURSERVERNAME;database=YOURDB;")
       
End Sub

Private Sub ReadFromDB_Click()

   
    sql = "Select * from ImgTable where Img_ID = " & InputBox("Enter the Image ID :", "Load Image from DB")
   
    Set Rs = Cn.OpenResultset(sql, rdOpenStatic, rdConcurReadOnly, rdExecDirect)
   
    If Rs.EOF Then
        MsgBox "Can't find Image by that ID"
        Exit Sub
    End If
   
    Open "pictemp" For Binary Access Write As 1
   
    Fl = Rs!Img_Bitmap.ColumnSize
   
    Chunks = Fl \ ChunkSize
    Fragment = Fl Mod ChunkSize
   
    ReDim Chunk(Fragment)
   
    Chunk() = Rs!Img_Bitmap.GetChunk(Fragment)
   
    Put 1, , Chunk()
   
    For I = 1 To Chunks
        ReDim Buffer(ChunkSize)
        Chunk() = Rs!Photo.GetChunk(ChunkSize)
        Put 1, , Chunk()
    Next
   
    Close 1
   
    Picture1.Picture = LoadPicture("pictemp")
   
    Kill "pictemp"
   
End Sub


Private Sub SaveToDB_Click()

   
    Dim Img_ID As Long
   
    Img_ID = InputBox("Enter the Image ID :", "Save Image to DB")
   
    sql = "Select * from ImgTable where Img_ID = " & Img_ID
   
    Set Rs = Cn.OpenResultset(sql, rdOpenDynamic, rdConcurValues, rdExecDirect)
   
    If Rs.EOF Then
        Rs.AddNew
        Rs!Img_ID = Img_ID
       
        Description = InputBox("Describe the picture", "Save Image to DB")
       
        Rs!Img_Description = Description
    Else
        Rs.Edit
    End If
   

SavePicture Picture1.Picture, "pictemp"

Open "pictemp" For Binary Access Read As 1
Fl = LOF(1)    ' Length of data in file

If Fl = 0 Then Close 1: Exit Sub

Chunks = Fl \ ChunkSize
Fragment = Fl Mod ChunkSize
Rs!Img_Bitmap.AppendChunk Null

ReDim Chunk(Fragment)
Get 1, , Chunk()
Rs!Img_Bitmap.AppendChunk Chunk()

ReDim Chunk(ChunkSize)
For I = 1 To Chunks
    Get 1, , Chunk()
    Rs!Img_Bitmap.AppendChunk Chunk()
Next

Close 1
Rs.Update
Rs.Close
Set Rs = Nothing
Kill "pictemp"

End Sub


0
 

Author Comment

by:kbakst
ID: 2398012
I guess the question I'd have to ask for this answer is:  why do YOU think it's better to store in the database?  If you can't come up with a reason, I'd have to give the credit to Ameba - even thought his name should be spelled Amoeba.  :)
0
 
LVL 15

Accepted Solution

by:
ameba earned 1600 total points
ID: 2398961
You CAN hold *small* pictures (icons, thumbnails) in database. Ameba also allows pictures in memo fields (users can paste picture into richtextbox).

But for normal pictures use files.

See also mark2150's comments in this 10 pts PAQ:
http://www.experts-exchange.com/Q.10183155
(Note: there is no code in that PAQ)
0
 

Author Comment

by:kbakst
ID: 2399641
This works for me.  800 points from me to Ameba in 2 days.  Worth every bit.

Kelly
0
 
LVL 15

Expert Comment

by:ameba
ID: 2401422
Thanks :)
0
 
LVL 3

Expert Comment

by:KhollAD
ID: 2408301
?!
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

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

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.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…

588 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