Store/view a scanned document?

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
kbakstAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amebaCommented:
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
sdland1Commented:
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
amebaCommented:
spam
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mcriderCommented:
ameba, spam?  What are you talking about?


Cheers!
0
kbakstAuthor Commented:
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
kbakstAuthor Commented:
sdland1 posted spam as a comment.
0
mcriderCommented:
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
amebaCommented:
>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
amebaCommented:
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
KhollADCommented:
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
kbakstAuthor Commented:
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
amebaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kbakstAuthor Commented:
This works for me.  800 points from me to Ameba in 2 days.  Worth every bit.

Kelly
0
amebaCommented:
Thanks :)
0
KhollADCommented:
?!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.