You are on page 1of 5

Image, Thumbnail and Database (VB.

Net)
This project is used to get image from disk file, convert it to thumbnail, save them to database, update or delete
database record. On another way, it can get image / thumbnail from database, save them on disk or display them
on DotNet indow!orm or eb!orm.
"t contains a stand#alone $%$ and a DotNet component D&& for developers, supporting '(& 'erver and )ccess
*D+.
To use the D&& in )',.Net, have a look of the "mage, Thumbnail and Database for )',.Net, which has more info
about displaying database image directly on -T*&.
The The Zipped Files ./ 011 2+, including $%$, D&& and *D+ sample3 are free to download here.
The Dependency: DotNet !rameork .free from *'3.
The ImageDB.EXE: is simply arranged. -owever, it helps how to use the component .see also the sample
code3. "t does three main jobs4 "mage to Thumbnail, to / from disk file5 "mage to database5 "mage from database.
The Database Setting: is for the D+ options. "t6ll generate and test the D+ 7onnection 'tring by 8D+ Table9
.retriving the Tables from database3. Once it6s tested and 8'ave9d, it won6t pop#up anymore. The saved ,D and
7onnection 'tring are secured by the ,roject Tool.
The Database: supports *' '(& 'erver and *' )ccess *D+ .no Oracle yet3, designed as4 .*D+ sample
included in the :",, no ,assword, ;serName5 users can add more 7olumns as wish, i.e. "mage<Date, "mage<'i=e
...3
Image Database Design
Column ame S!" Data Type #ccess Data Type
"mage<"D "nt, ,rimary2ey )utoNumber, ,rimary2ey
"mage<Name N>ar7har .0113 Te?t .0113
"mage<Data "mage O&$ Object .+inary Data3
"mage<Thumbnail "mage O&$ Object .+inary Data3
"mage<Description N>ar7har .01113 Te?t .@AA3
The ImageDB.D"": is a DotNet component for both indow!orm and eb!orm, used in developer6s own
project .just add the D&& into the project references3.
Notice4 Three *ethods here return "mage object as Data Type, which is designed for indow!orm6s ,icture+o?
7ontrol that takes "mage object directly to display. -owever, to display "mage on eb!orm directly without fisrt
saving a temp file is not that starightforward, do look the sample code on "mage / Thumbnail and Database for
)',.Net.
Image Database Component $sage
Dim ImgDB #s e% #S&Simply.ImageDB
&'ope'ties Type De(ault Desc'iption
Bet"mageName,ath 'tring # the "mage !ile .full path C name3 to be opened from disk
'ave"mageName,ath 'tring # the "mage !ile .full path C name3 to be saved to disk
ThumbnailName,ath 'tring # Thumbnail !ile .full path C name3 to be saved to disk
ThumbnailType 'tring Dpeg
Thumbnail Type to be converted4
bmp/emf/e?i/e?if/gif/ico/icon/jpg/jpeg/png/tif/tiff/wmf
Thumbnailidth E "nteger 011 Thumbnail idth to be converted .pi?el3 from the "mage
Thumbnail-eight E "nteger 011 Thumbnail -eight to be converted .pi?el3 from the "mage
)ddThumbnail +oolean !alse hether store Thumbnail into the Database
D+Type E 'tring *D+ Database Type4 F'(&F or F*D+F
D+Table 'tring "mageTable Database Table Name
D+7onn'tring 'tring #
Database 7onnection 'tring, generated by the Database
'etting, or see more info here
"mage"D "nteger 0
The "mage<"D number, to get / delete/update the "mage from
Database
"mageName 'tring # The "mage<Name, to add / update the "mage info to Database
"mageDescription 'tring #
The "mage<Description, to add / update the "mage info to
Database
)ethods Type De(ault Desc'iption
"mageToThumbnail.3 "mage #
7onvert the "mage from the database / file to Thumbnail, return
"mage
'ave"mage.3 # # 'ave the "mage from the database / file to disk
'aveThumbnail.3 # # 'ave the Thumbnail from the database / file to disk
)ddD+"mage.3 # # )dd the "mage / Thumbnail to the database
BetD+"mage.3 "mage # Bet the "mage from the database by "mage"D
BetD+Thumbnail.3 "mage # Bet the Thumbnail from the database by "mage"D
;pdateD+"mage.3 # # ;pdate the "mage Name and Description in the database
DeleteD+"mage.3 # # Delete the "mage record from the database by "mage"D
E "n the Trial, Thumbnailidth G Thumbnail-eight G 011, D+Type G F*D+F, no options available.
The Sample Code (o' #S&.et: is slightly different from indow!orm, please have a look at "mage, Thumbnail
and Database for )',.Net, which also shows how to display database image directly on -T*& by )',.
The Sample Code (o' *B.et +,indo% Fo'm-: will walkthrough all these methods in the D&&. hen test,
using Try ... 7atch ... $nd Try is always recommended. There should be a ,icture+o?0 and a ,icture+o?TN control
on the !orm.
''''' first declare some Module Variables
Private IMGDB As New ASPSimply.ImaeDB!" ' Most
importa#t to i#itiali$e t%e compo#e#t
Private mstrGetImaeNamePat% As Stri# & Applicatio#.StartupPat% '
()sa%ara**.+p(
Private mstrSaveImaeNamePat% As Stri# & Applicatio#.StartupPat% '
()sa%ara*,.+p(
Private mstr-%umb#ailNamePat% As Stri# & Applicatio#.StartupPat% '
()sa%ara-N.+p(
Private mstrDB.o##Stri# As Stri# &
(Provider&Microsoft./et.012DB.3.*4 Data Source&( 5
' Applicatio#.StartupPat% ' ()ImaeDB.MDB(
Private mstrImaeName As Stri# & (Sa%ara**.+p(
Private mstrImaeDescriptio# As Stri# & (Sa%ara**.+p 6 -a7e# by
myself 8"(
Private Sub Imae-o-%umb#ail5Save5AddDB!"
9it% IMGDB
.GetImaeNamePat% & mstrGetImaeNamePat%
' .-%umb#ail9idt% & ,** ' default
' .-%umb#ail:ei%t & ,** ' default
' .-%umb#ail-ype & (/pe( ' default
PictureBo;-N.Imae & .Imae-o-%umb#ail!" ' .o#vertt
Imae to -%umb#ail
.-%umb#ailNamePat% & mstr-%umb#ailNamePat%
.Save-%umb#ail!" ' Save
-%umb#ail to dis7
.DB.o##Stri# & mstrDB.o##Stri#
' .DB-ype & (MDB( ' default
' .DB-able & (Imae-able( ' default
.Add-%umb#ail & -rue ' defult8
<alse
.ImaeName & mstrImaeName
.ImaeDescriptio# & mstrImaeDescriptio#
.AddDBImae!" ' Add Imae
a#d -%umb#ail to DB
2#d 9it%
2#d Sub
Private Sub GetDBImae5-%umb#ail5Save!"
9it% IMGDB
.DB.o##Stri# & mstrDB.o##Stri#
' .DB-ype & (MDB( ' default
' .DB-able & (Imae-able( ' default
.ImaeID & , ' defult
PictureBo;,.Imae & .GetDBImae!" ' Get Imae
from DB
.SaveImaeNamePat% & mstrSaveImaeNamePat%
.SaveImae!" ' Save Imae
to dis7
PictureBo;-N.Imae & .GetDB-%umb#ail!" ' Get
-%umb#ail from DB
.-%umb#ailNamePat% & mstr-%umb#ailNamePat%
.Save-%umb#ail!" ' Save
-%umb#ail to dis7
2#d 9it%
2#d Sub
Private Sub =pdateDBImae!"
9it% IMGDB
.DB.o##Stri# & mstrDB.o##Stri#
' .DB-ype & (MDB( ' default
' .DB-able & (Imae-able( ' default
.ImaeID & > ' default8 ,
.ImaeName & (=pdate ( ' mstrImaeName
.ImaeDescriptio# & (=pdate ( ' mstrImaeDescriptio#
.=pdateDBImae!" ' =pdate
ImaeName a#d ImaeDescriptio#
2#d 9it%
2#d Sub
Private Sub DeleteDBImae!"
9it% IMGDB
.DB.o##Stri# & mstrDB.o##Stri#
' .DB-ype & (MDB( ' default
' .DB-able & (Imae-able( ' default
.ImaeID & > ' default8 ,
.DeleteDBImae!" ' Delete
Imae a#d -%umb#ail record from DB
2#d 9it%
2#d Sub
Private Sub <orm,5.losi#!ByVal se#der As 0b+ect? 5
ByVal e As
System..ompo#e#tModel..a#cel2ve#tArs" :a#dles MyBase..losi#
If Not IMGDB Is Not%i# -%e# IMGDB & Not%i# ' Voila @
Is#'t easy to use t%is compo#e#t A
2#d Sub
The T'ial .s. /egiste'ed: "n the Trial, both Thumbnailidth and Thumbnail-eight use their default values
.0113, and D+Type G F*D+F .'(& server disabled3. To remove the Trial limitations, please Hegister this ,roduct,
or simply ,ay by ,ay,al.
Thank you for your support I
The Tips 0 otes:
J *ouse#over those buttons for pop#up tips.
J The =ipped sample )ccess *D+ has no ,assword, ;serName.
J The database setting is needed only once after 8'ave9 it.
J To 8;pdate9 the database record, edit the DataBrid directly by slow double#click.
J 8)djust TN9 the Thumbnail Type and 'i=e before 8'ave TN9 or 8)dd "mage9.
J To display database image directly on -T*&, neither )',.Net nor the D&& component needed5 or indirectly
"mage to Thumbnail for )',.Net3
J !or )',.Net, just call the routines "mageToThumbnail.3, BetD+"mage.3 or BetD+Thumbnail.3 and no need to
assign them to "mage objects.

You might also like