Goodangel Matope
asked on
Images in a database
I would like to a database to have a person's details and their photo. How do I link each photo to a field in the database. Someone talked of BLOB fileds and I have no idea how it is done. Please help!
what database?
ASKER
Paradox (I presume that comes default with Delphi 4)
To load a new Picture just use :
DbImage1.Picture.LoadFromF ile ('C:\xxx.bmp');
Best Regards
Cesario
DbImage1.Picture.LoadFromF
Best Regards
Cesario
which image-formats u will use?
ASKER
I would like to use jpegs, and tiffs if possible (tiff for image of identification card.)
well, from my paq
first the bad news,
you cannot use the graphic-fieldtyp for jpeg-images, also you can't use the
tdbimage-component for visualzing the image.
the soloution:
a sample
first in the paradox structure the BlobField is type Binary
and now follows a sample-unit,
which stores and get the JPeg
unit db_pict_u;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask, Menus, jpeg; // JPeg unit is used
type
TForm1 = class(TForm)
DBEdit1: TDBEdit; // A other DBField
DBNavigator1: TDBNavigator;
Table1: TTable;
DataSource1: TDataSource;
PopupMenu1: TPopupMenu; // a Popup linked to Image1
LoadPicture1: TMenuItem; // the MenuItem of the Popup
OpenDialog1: TOpenDialog; // OpenDialog
Image1: TImage; // Visual Output for the JPeg
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure LoadJPEG1Click(Sender: TObject); // File Load and Store in DB
procedure Table1AfterScroll(DataSet: TDataSet); // Get JPeg and Display in Image1
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
JPegImage : TJpegImage; //A temporary JPeg-Object
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
JpegImage := TJPegImage.Create; // Create JPeg-Object
Table1.Open;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Table1.Close;
JPegImage.Free; // Free JPeg-Object
end;
procedure TForm1.LoadJPEG1Click(Send er: TObject);
Var
MyBlobStream : TBlobStream; // Streams
MyJPegStream : TMemoryStream;
begin
if (Table1.State = dsEdit) or
(Table1.State = dsInsert) then // Do only if in edit mode
begin
If opendialog1.Execute then // If file selected
begin
if Table1.FieldByName('Bild2' ).IsBlob then // this line can deleted
begin
MyJPegStream := TMemoryStream.Create; // Handle JPegFile
JPegImage.LoadFromFile(ope ndialog1.f ilename);
JPegImage.SaveToStream(MyJ PegStream) ;
// Prepare Blob
MyBlobStream :=
TBlobStream.Create(TBlobFi eld(Table1 .FieldByNa me('Bild2' )),bmReadW rite);
MyBlobStream.CopyFrom(MyJP egStream,0 ); // Copy JPeg into BlobField
Image1.Picture.Assign(JPeg Image); // Display
MyJPegStream.Free; //Free all
MyBlobStream.Free;
end;
end;
end else ShowMessage('Table is not in Edit Mode!');
end;
procedure TForm1.Table1AfterScroll(D ataSet: TDataSet);
Var
MyBlobStream : TBlobStream;
begin
// Do Only if a JPeg available
if (Table1.FieldByName('Bild2 ').IsBlob) and (not(Table1.FieldByName('B ild2').IsN ull)) then
begin
// Prepare Streams
MyBlobStream :=
TBlobStream.Create(TBlobFi eld(Table1 .FieldByNa me('Bild2' )),bmRead) ;
JPegImage.LoadFromStream(M yBlobStrea m);
Image1.Picture.Assign(JPeg Image); //Display JPeg
MyBlobStream.Free; // Free Stream
end
else image1.Picture := Nil; // No JPeg saved disable display
end;
end.
meikl
first the bad news,
you cannot use the graphic-fieldtyp for jpeg-images, also you can't use the
tdbimage-component for visualzing the image.
the soloution:
a sample
first in the paradox structure the BlobField is type Binary
and now follows a sample-unit,
which stores and get the JPeg
unit db_pict_u;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask, Menus, jpeg; // JPeg unit is used
type
TForm1 = class(TForm)
DBEdit1: TDBEdit; // A other DBField
DBNavigator1: TDBNavigator;
Table1: TTable;
DataSource1: TDataSource;
PopupMenu1: TPopupMenu; // a Popup linked to Image1
LoadPicture1: TMenuItem; // the MenuItem of the Popup
OpenDialog1: TOpenDialog; // OpenDialog
Image1: TImage; // Visual Output for the JPeg
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure LoadJPEG1Click(Sender: TObject); // File Load and Store in DB
procedure Table1AfterScroll(DataSet:
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
JPegImage : TJpegImage; //A temporary JPeg-Object
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
JpegImage := TJPegImage.Create; // Create JPeg-Object
Table1.Open;
end;
procedure TForm1.FormDestroy(Sender:
begin
Table1.Close;
JPegImage.Free; // Free JPeg-Object
end;
procedure TForm1.LoadJPEG1Click(Send
Var
MyBlobStream : TBlobStream; // Streams
MyJPegStream : TMemoryStream;
begin
if (Table1.State = dsEdit) or
(Table1.State = dsInsert) then // Do only if in edit mode
begin
If opendialog1.Execute then // If file selected
begin
if Table1.FieldByName('Bild2'
begin
MyJPegStream := TMemoryStream.Create; // Handle JPegFile
JPegImage.LoadFromFile(ope
JPegImage.SaveToStream(MyJ
// Prepare Blob
MyBlobStream :=
TBlobStream.Create(TBlobFi
MyBlobStream.CopyFrom(MyJP
Image1.Picture.Assign(JPeg
MyJPegStream.Free; //Free all
MyBlobStream.Free;
end;
end;
end else ShowMessage('Table is not in Edit Mode!');
end;
procedure TForm1.Table1AfterScroll(D
Var
MyBlobStream : TBlobStream;
begin
// Do Only if a JPeg available
if (Table1.FieldByName('Bild2
begin
// Prepare Streams
MyBlobStream :=
TBlobStream.Create(TBlobFi
JPegImage.LoadFromStream(M
Image1.Picture.Assign(JPeg
MyBlobStream.Free; // Free Stream
end
else image1.Picture := Nil; // No JPeg saved disable display
end;
end.
meikl
just to remark,
its just a sample,
therefore i've no try..except, try..finally
blocks inserted, which should be done for daus (users, which are not carefull)
meikl
its just a sample,
therefore i've no try..except, try..finally
blocks inserted, which should be done for daus (users, which are not carefull)
meikl
ASKER
Does that mean I cannot save to the BLOB field? How will I access the same image again in future?
?,
you can access and replace/save the jpeg-image in the blob-field as described above, you can also get it back to a file (this method is not included in the sample above, but it isn't difficult)
meikl
you can access and replace/save the jpeg-image in the blob-field as described above, you can also get it back to a file (this method is not included in the sample above, but it isn't difficult)
meikl
Hi,
An Artikel:Using Jpegs with Paradox
http://www.delphi3000.com/article.asp?ID=1315
Best Regards Cesario
An Artikel:Using Jpegs with Paradox
http://www.delphi3000.com/article.asp?ID=1315
Best Regards Cesario
well cesario,
but this article is just not complete,
because if you use table.fieldname as the author mentioned
you will have a tfield, and then you must do an additional conversion to tblobfield to get access to the streaming capabilities.
but at least its just the same as my sample
meikl
but this article is just not complete,
because if you use table.fieldname as the author mentioned
you will have a tfield, and then you must do an additional conversion to tblobfield to get access to the streaming capabilities.
but at least its just the same as my sample
meikl
sorry cesario,
didn't read the beginning of the article exactly,
where the author explains to create persistant fields.
well with persistant fields the code in the article will work also
meikl ;-)
didn't read the beginning of the article exactly,
where the author explains to create persistant fields.
well with persistant fields the code in the article will work also
meikl ;-)
any problems, goodangel?
goodangel, are you alive?
ASKER
Hie Kretzschmar. I am alive and I am wondering if I can also use tiffs. I tried the stuff above and I have not managed to get it to work. I will accept your answer though. Will tiffs work in a paradox database?
hi goodangel,
glad to hear, that you're alive :-)
Tiff will work
in the main manner,
but you will need a tiff-object like the jpeg-object for the visualizing from a third partydevelopment, because tiff is not included with delphi.
take a look to
http://www.torry.ru/vcl/graphics/packs/tiffpack.zip
i've a sample-app for jpg, which i can send you, if you leave your email address here.
and points only, if you get it work
meikl ;-)
glad to hear, that you're alive :-)
Tiff will work
in the main manner,
but you will need a tiff-object like the jpeg-object for the visualizing from a third partydevelopment, because tiff is not included with delphi.
take a look to
http://www.torry.ru/vcl/graphics/packs/tiffpack.zip
i've a sample-app for jpg, which i can send you, if you leave your email address here.
and points only, if you get it work
meikl ;-)
>in the main manner,
should be read:
in the same manner,
meikl :-)
should be read:
in the same manner,
meikl :-)
ASKER
Meikl
My email is goodangelma@ncr.co.zw
Please email the sample app. I will be most obliged.
My email is goodangelma@ncr.co.zw
Please email the sample app. I will be most obliged.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.