cc042297
asked on
JPG to Paradox
Hi,
Can somebody tell me how to store the content of a JPG photo to a graphic field in a Paradox table? (I understand that Paradox cannot store jpg graphics.)
Regards, CC.
Can somebody tell me how to store the content of a JPG photo to a graphic field in a Paradox table? (I understand that Paradox cannot store jpg graphics.)
Regards, CC.
You can load file into a stream or just use TFileStream
Set table field type to BLOB and load the stream into a blob something like this:
function tinsert.SaveToBlob(const Stream: TStream; const AField: TField): boolean;
var
FieldStr: string;
PFieldStr: PChar;
begin
Result := false;
if (Assigned(AField)) and (Assigned(Stream)) then begin
try
Stream.Seek(0,0);
SetLength(FieldStr, Stream.Size);
PFieldStr := PChar(FieldStr);
Stream.Read(PFieldStr^, Stream.Size);
AField.Value := FieldStr;
Result := true;
except
end;
end;
end;
Set table field type to BLOB and load the stream into a blob something like this:
function tinsert.SaveToBlob(const Stream: TStream; const AField: TField): boolean;
var
FieldStr: string;
PFieldStr: PChar;
begin
Result := false;
if (Assigned(AField)) and (Assigned(Stream)) then begin
try
Stream.Seek(0,0);
SetLength(FieldStr, Stream.Size);
PFieldStr := PChar(FieldStr);
Stream.Read(PFieldStr^, Stream.Size);
AField.Value := FieldStr;
Result := true;
except
end;
end;
end;
ASKER
Hi MNasman & MrGhost!
Thanks for helping me!
MNasman:
I've sent you an e-mail.
MrGhost:
Do you think that a DBImage can display the photo if I store it in a BLOB instead of a graphic field? I can't see from your code, how it connencts to the jpg file.
Thanks for helping me!
MNasman:
I've sent you an e-mail.
MrGhost:
Do you think that a DBImage can display the photo if I store it in a BLOB instead of a graphic field? I can't see from your code, how it connencts to the jpg file.
ASKER
Hi MNasman & MrGhost!
Thanks for helping me!
MNasman:
I've sent you an e-mail.
MrGhost:
Do you think that a DBImage can display the photo if I store it in a BLOB instead of a graphic field? I can't see from your code, how it connencts to the jpg file.
Regards, CC.
Thanks for helping me!
MNasman:
I've sent you an e-mail.
MrGhost:
Do you think that a DBImage can display the photo if I store it in a BLOB instead of a graphic field? I can't see from your code, how it connencts to the jpg file.
Regards, CC.
ASKER
Hi MNasman & MrGhost!
Thanks for helping me!
MNasman:
I've sent you an e-mail.
MrGhost:
Do you think that a DBImage can display the photo if I store it in a BLOB instead of a graphic field? I can't see from your code, how it connencts to the jpg file.
Regards, CC.
Thanks for helping me!
MNasman:
I've sent you an e-mail.
MrGhost:
Do you think that a DBImage can display the photo if I store it in a BLOB instead of a graphic field? I can't see from your code, how it connencts to the jpg file.
Regards, CC.
I think so
ok i just try to use this:
procedure TForm1.Button2Click(Sender : TObject);
var
bla:TBLobField;
begin
table1.Insert;
bla := TBlobField(table1.FieldByN ame('Image '));
bla.LoadFromFile('c:\bla.b mp');
table1.Post;
end;
it works ok with BMP but fails with JPG, so i guess there is some other options for which i dont know or you can convert JPG to BMP!
procedure TForm1.Button2Click(Sender
var
bla:TBLobField;
begin
table1.Insert;
bla := TBlobField(table1.FieldByN
bla.LoadFromFile('c:\bla.b
table1.Post;
end;
it works ok with BMP but fails with JPG, so i guess there is some other options for which i dont know or you can convert JPG to BMP!
ASKER
MrGhost
I have tried the same with the same result.
TImage.LoadFromFile reads jpg without any problem. Delphi help suggests assigning its value to a Field. This is what I did:
Image1.Picture.LoadFromFil e(Picture_ Dir + Picture_ID + '.jpg');
TGraphicField(T1.FieldByNa me('Pictur e')).Assig n(Image1.P icture);
Though TImage can read JPG, this far I was not able to find any way to get the picture out of it. :(
TDBImage also has a LoadFromFile method, but it does not read JPG. I tried to seek for help at EE after trying all these. I did not want to beleave, that Delphi is really missing JPG converting. :))
Regards, CC.
I have tried the same with the same result.
TImage.LoadFromFile reads jpg without any problem. Delphi help suggests assigning its value to a Field. This is what I did:
Image1.Picture.LoadFromFil
TGraphicField(T1.FieldByNa
Though TImage can read JPG, this far I was not able to find any way to get the picture out of it. :(
TDBImage also has a LoadFromFile method, but it does not read JPG. I tried to seek for help at EE after trying all these. I did not want to beleave, that Delphi is really missing JPG converting. :))
Regards, CC.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
MrGhost
I have tried the same with the same result.
TImage.LoadFromFile reads jpg without any problem. Delphi help suggests assigning its value to a Field. This is what I did:
Image1.Picture.LoadFromFil e(Picture_ Dir + Picture_ID + '.jpg');
TGraphicField(T1.FieldByNa me('Pictur e')).Assig n(Image1.P icture);
Though TImage can read JPG, this far I was not able to find any way to get the picture out of it. :(
TDBImage also has a LoadFromFile method, but it does not read JPG. I tried to seek for help at EE after trying all these. I did not want to beleave, that Delphi is really missing JPG converting. :))
Regards, CC.
I have tried the same with the same result.
TImage.LoadFromFile reads jpg without any problem. Delphi help suggests assigning its value to a Field. This is what I did:
Image1.Picture.LoadFromFil
TGraphicField(T1.FieldByNa
Though TImage can read JPG, this far I was not able to find any way to get the picture out of it. :(
TDBImage also has a LoadFromFile method, but it does not read JPG. I tried to seek for help at EE after trying all these. I did not want to beleave, that Delphi is really missing JPG converting. :))
Regards, CC.
hi,
an older sample using graphicEX from www.lischke-online.de
(enables many kinds of pictureformats to display)
for storing in the paradox-table, the blobfield should be of binary type,
this sample stores any file into the blobfield
unit db_picture_u;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs,
ExtDlgs, Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask, ComCtrls,
GraphicEx, Graphics;
type
TForm1 = class(TForm) //db-navigation
Table1: TTable; //the table, where the images are stored
DataSource1: TDataSource;
Panel1: TPanel;
ProgressBar1: TProgressBar;
DBNavigator1: TDBNavigator;
Button1: TButton;
Panel2: TPanel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Label1: TLabel;
Label2: TLabel;
Table2: TTable;
ScrollBox1: TScrollBox;
Image1: TImage;
Button2: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject); //execute load and preStore to the Blobfield
procedure FormCreate(Sender: TObject); //TableOpen
procedure FormDestroy(Sender: TObject); //TableClose
procedure Table1AfterScroll(DataSet: TDataSet);
procedure Table1BeforeScroll(DataSet : TDataSet);
procedure Image1Progress(Sender: TObject; Stage: TProgressStage;
PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
const Msg: String);
procedure Table1AfterInsert(DataSet: TDataSet);
procedure Table1BeforePost(DataSet: TDataSet);
procedure Button2Click(Sender: TObject);
private
Function DisplayImage(AStream : TStream; AExtension : String) : Boolean;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function TForm1.DisplayImage(AStrea m : TStream; AExtension : String) : Boolean;
Var
//Extended Graphicformats
AExGraphicClass: TGraphicExGraphicClass;
AExGraphic: TGraphicExGraphic;
//Standard Graphicformats
AGraphicClass : TGraphicClass;
AGraphic : TGraphic;
OldPosition : Integer;
begin
Result := False; //do as that cannot be loaded
If Assigned(AStream) then
try
OldPosition := AStream.Position;
try
AStream.Position := 0; //Remember Streams Position
//Check for Extended Graphicformats
AExGraphicClass := GraphicEx.FileFormatList.G raphicFrom Content(AS tream);
if AExGraphicClass <> Nil then
begin
AExGraphic := AExGraphicClass.Create;
try
//Load Extended Graphicformats
AExGraphic.LoadFromStream( AStream);
Image1.Picture.Graphic := AExGraphic;
Result := True;
finally
AExGraphic.Free;
end;
end
else
begin
//Check for Standard Graphicformats
AGraphicClass := GraphicEx.FileFormatList.G raphicFrom Extension( AExtension );
if AGraphicClass <> Nil then
begin
AGraphic := AGraphicClass.Create;
try
//Load Standard Graphicformats
AGraphic.LoadFromStream(AS tream);
Image1.Picture.Graphic := AGraphic;
Result := True;
finally
AGraphic.Free;
end;
end;
end;
finally
AStream.Position := OldPosition;
end;
except
Raise;
end;
end;
//Load any file into the BlobField
procedure TForm1.Button1Click(Sender : TObject);
Var
ExtS : String; //Holds The Extension
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('Pictur e').IsBlob then // this line can deleted
begin //remember the Extension
ExtS := copy(AnsiUpperCase(Extract FileExt(Op enDialog1. FileName)) ,2,MaxLong Int);
try
TBlobField(Table1.FieldByN ame('Pictu re')).Load FromFile(o pendialog1 .filename) ; //Store the File in the Blob
Table1.FieldByName('Typ'). AsString := ExtS; //Store the Extension in the Grafic-TypField
try
//try to load Image, also from file
image1.Picture.LoadFromFil e(opendial og1.filena me);
except
//failed to load Image, also from file
showmessage('Cannot display this File as Imageformat'+#10+
'File is loaded anyway');
image1.Picture := Nil;
end;
except
//Any Error
Raise;
end;
end;
end;
end else ShowMessage('Table is not in Edit Mode!');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//some prepare
Opendialog1.Filter :=
GraphicEx.FileFormatList.G etGraphicF ilter([],f stBoth,[fo IncludeAll ,foInclude Extension] ,nil);
Opendialog1.Options := [ofFileMustExist,ofEnableS izing];
Table1.Open;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//some unprepare
Table1.Close;
end;
//After Scrolling the TableCursor
procedure TForm1.Table1AfterScroll(D ataSet: TDataSet);
Var
AStream : TMemoryStream;
begin
try
try
// Do Only if a Picture available
if (Table1.FieldByName('Pictu re').IsBlo b) and
(not(Table1.FieldByName('P icture').I sNull)) then
begin //create a stream
AStream := TMemoryStream.Create;
try
//Store the BlobContent into the Stream
TBlobField(Table1.FieldByN ame('Pictu re')).Save ToStream(A Stream);
//Try to Display the image
if not DisplayImage(AStream,Table 1.FieldByN ame('Typ') .AsString) then
begin
//Failed to Display the image
image1.Picture.assign(Nil) ;
showmessage('Cannot display this File as Image');
end;
finally
AStream.Free; // Free Stream
end;
end
else image1.Picture.assign(Nil) ; // No Picture saved disable display
Finally
//Restore Cursor
screen.Cursor := crDefault;
ProgressBar1.Position := 100;
end;
except
//Any Error
Raise;
end;
end;
//Prepare progress
procedure TForm1.Table1BeforeScroll( DataSet: TDataSet);
begin
screen.cursor := crhourglass;
ProgressBar1.Position := 0;
end;
//some Progress
procedure TForm1.Image1Progress(Send er: TObject; Stage: TProgressStage;
PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
const Msg: String);
begin
Progressbar1.Position := Percentdone;
end;
//PreInit index
procedure TForm1.Table1AfterInsert(D ataSet: TDataSet);
begin
Table1.FieldByName('ID').A sFloat := -1;
end;
//Supply index, not a optimal method, but works in local enviroments
procedure TForm1.Table1BeforePost(Da taSet: TDataSet);
begin
If table1.State = dsInsert then
begin
table2.open;
table2.last;
Table1.FieldByName('ID').A sFloat := Table2.FieldByName('ID').A sFloat + 1;
Table2.Close;
end;
end;
//Save any Blobcontent to a file
procedure TForm1.Button2Click(Sender : TObject);
begin
if (Table1.FieldByName('Pictu re').IsBlo b) and
(not(Table1.FieldByName('P icture').I sNull)) then
begin
SaveDialog1.Filter := '*.'+lowercase(Table1.Fiel dByName('T yp').AsStr ing);
SaveDialog1.Filter := SaveDialog1.Filter+'|'+Sav eDialog1.F ilter;
SaveDialog1.DefaultExt := lowercase(Table1.FieldByNa me('Typ'). AsString);
if SaveDialog1.Execute then
try
TBlobField(Table1.FieldByN ame('Pictu re')).Save ToFile(Sav eDialog1.F ileName);
except
Raise;
end;
end
else Showmessage('Nothing to Restore');
end;
end.
hope this helps
(if needed, then i can send this app with a sample table)
meikl ;-)
an older sample using graphicEX from www.lischke-online.de
(enables many kinds of pictureformats to display)
for storing in the paradox-table, the blobfield should be of binary type,
this sample stores any file into the blobfield
unit db_picture_u;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs,
ExtDlgs, Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask, ComCtrls,
GraphicEx, Graphics;
type
TForm1 = class(TForm) //db-navigation
Table1: TTable; //the table, where the images are stored
DataSource1: TDataSource;
Panel1: TPanel;
ProgressBar1: TProgressBar;
DBNavigator1: TDBNavigator;
Button1: TButton;
Panel2: TPanel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Label1: TLabel;
Label2: TLabel;
Table2: TTable;
ScrollBox1: TScrollBox;
Image1: TImage;
Button2: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject); //execute load and preStore to the Blobfield
procedure FormCreate(Sender: TObject); //TableOpen
procedure FormDestroy(Sender: TObject); //TableClose
procedure Table1AfterScroll(DataSet:
procedure Table1BeforeScroll(DataSet
procedure Image1Progress(Sender: TObject; Stage: TProgressStage;
PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
const Msg: String);
procedure Table1AfterInsert(DataSet:
procedure Table1BeforePost(DataSet: TDataSet);
procedure Button2Click(Sender: TObject);
private
Function DisplayImage(AStream : TStream; AExtension : String) : Boolean;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function TForm1.DisplayImage(AStrea
Var
//Extended Graphicformats
AExGraphicClass: TGraphicExGraphicClass;
AExGraphic: TGraphicExGraphic;
//Standard Graphicformats
AGraphicClass : TGraphicClass;
AGraphic : TGraphic;
OldPosition : Integer;
begin
Result := False; //do as that cannot be loaded
If Assigned(AStream) then
try
OldPosition := AStream.Position;
try
AStream.Position := 0; //Remember Streams Position
//Check for Extended Graphicformats
AExGraphicClass := GraphicEx.FileFormatList.G
if AExGraphicClass <> Nil then
begin
AExGraphic := AExGraphicClass.Create;
try
//Load Extended Graphicformats
AExGraphic.LoadFromStream(
Image1.Picture.Graphic := AExGraphic;
Result := True;
finally
AExGraphic.Free;
end;
end
else
begin
//Check for Standard Graphicformats
AGraphicClass := GraphicEx.FileFormatList.G
if AGraphicClass <> Nil then
begin
AGraphic := AGraphicClass.Create;
try
//Load Standard Graphicformats
AGraphic.LoadFromStream(AS
Image1.Picture.Graphic := AGraphic;
Result := True;
finally
AGraphic.Free;
end;
end;
end;
finally
AStream.Position := OldPosition;
end;
except
Raise;
end;
end;
//Load any file into the BlobField
procedure TForm1.Button1Click(Sender
Var
ExtS : String; //Holds The Extension
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('Pictur
begin //remember the Extension
ExtS := copy(AnsiUpperCase(Extract
try
TBlobField(Table1.FieldByN
Table1.FieldByName('Typ').
try
//try to load Image, also from file
image1.Picture.LoadFromFil
except
//failed to load Image, also from file
showmessage('Cannot display this File as Imageformat'+#10+
'File is loaded anyway');
image1.Picture := Nil;
end;
except
//Any Error
Raise;
end;
end;
end;
end else ShowMessage('Table is not in Edit Mode!');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//some prepare
Opendialog1.Filter :=
GraphicEx.FileFormatList.G
Opendialog1.Options := [ofFileMustExist,ofEnableS
Table1.Open;
end;
procedure TForm1.FormDestroy(Sender:
begin
//some unprepare
Table1.Close;
end;
//After Scrolling the TableCursor
procedure TForm1.Table1AfterScroll(D
Var
AStream : TMemoryStream;
begin
try
try
// Do Only if a Picture available
if (Table1.FieldByName('Pictu
(not(Table1.FieldByName('P
begin //create a stream
AStream := TMemoryStream.Create;
try
//Store the BlobContent into the Stream
TBlobField(Table1.FieldByN
//Try to Display the image
if not DisplayImage(AStream,Table
begin
//Failed to Display the image
image1.Picture.assign(Nil)
showmessage('Cannot display this File as Image');
end;
finally
AStream.Free; // Free Stream
end;
end
else image1.Picture.assign(Nil)
Finally
//Restore Cursor
screen.Cursor := crDefault;
ProgressBar1.Position := 100;
end;
except
//Any Error
Raise;
end;
end;
//Prepare progress
procedure TForm1.Table1BeforeScroll(
begin
screen.cursor := crhourglass;
ProgressBar1.Position := 0;
end;
//some Progress
procedure TForm1.Image1Progress(Send
PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
const Msg: String);
begin
Progressbar1.Position := Percentdone;
end;
//PreInit index
procedure TForm1.Table1AfterInsert(D
begin
Table1.FieldByName('ID').A
end;
//Supply index, not a optimal method, but works in local enviroments
procedure TForm1.Table1BeforePost(Da
begin
If table1.State = dsInsert then
begin
table2.open;
table2.last;
Table1.FieldByName('ID').A
Table2.Close;
end;
end;
//Save any Blobcontent to a file
procedure TForm1.Button2Click(Sender
begin
if (Table1.FieldByName('Pictu
(not(Table1.FieldByName('P
begin
SaveDialog1.Filter := '*.'+lowercase(Table1.Fiel
SaveDialog1.Filter := SaveDialog1.Filter+'|'+Sav
SaveDialog1.DefaultExt := lowercase(Table1.FieldByNa
if SaveDialog1.Execute then
try
TBlobField(Table1.FieldByN
except
Raise;
end;
end
else Showmessage('Nothing to Restore');
end;
end.
hope this helps
(if needed, then i can send this app with a sample table)
meikl ;-)
and again a more older and more simple sample
//Sample unit for Storing JPG-Images in the JPeg-Format
//in a BlobField in Paradox
//It is recommended, that the BlobField in Paradox is
//Typ Binary, not Graphic, because the file will be stored
//Free for Use
//Appendix: Its a sample, therefore no try, except, finally blocks included
//Created January 1999
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)
DBNavigator1: TDBNavigator;
Table1: TTable;
DataSource1: TDataSource;
PopupMenu1: TPopupMenu; // a Popup linked to Image1
LoadPicture1: TMenuItem; // the MenuItem of the Popup
OpenDialog1: TOpenDialog;
Image1: TImage;
DBEdit1: TDBEdit; // A other DBField
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
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;
//Store
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 (only JPeg-Files)
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;
//Get
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);
MyBlobStream.Free; // Free Stream
end
else image1.Picture := Nil; // No JPeg saved disable display
end;
end.
meikl ;-)
//Sample unit for Storing JPG-Images in the JPeg-Format
//in a BlobField in Paradox
//It is recommended, that the BlobField in Paradox is
//Typ Binary, not Graphic, because the file will be stored
//Free for Use
//Appendix: Its a sample, therefore no try, except, finally blocks included
//Created January 1999
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)
DBNavigator1: TDBNavigator;
Table1: TTable;
DataSource1: TDataSource;
PopupMenu1: TPopupMenu; // a Popup linked to Image1
LoadPicture1: TMenuItem; // the MenuItem of the Popup
OpenDialog1: TOpenDialog;
Image1: TImage;
DBEdit1: TDBEdit; // A other DBField
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
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;
//Store
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 (only JPeg-Files)
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;
//Get
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 ;-)
hi again,
just about
>JPG photo to a graphic field
is not possible, except you convert the jpg-file into a bitmap
thats just easy, if needed i could assist with this,
but it would be better to restructure your table,
and let your blobfield to be of binary-type instead of graphic-type,
because the bde-engine stores by a graphic type additional typ-
information in front of the blob-content (4Bytes)
meikl ;-)
just about
>JPG photo to a graphic field
is not possible, except you convert the jpg-file into a bitmap
thats just easy, if needed i could assist with this,
but it would be better to restructure your table,
and let your blobfield to be of binary-type instead of graphic-type,
because the bde-engine stores by a graphic type additional typ-
information in front of the blob-content (4Bytes)
meikl ;-)
Hello CC
I didn't get ur email, anyway here's the sample
the table Structure
PicId : No
PicDesc : Text
Pic : Blob
add image component and link the first two fields with the DBEdit boxes and add image component, cuz DBImage doesn't support the jpeg format
also add open dialog, two buttns and dbgrid
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, DBCtrls, Db, DBTables, Grids, DBGrids, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
Table1PicID: TFloatField;
Table1PicDesc: TStringField;
Table1Pic: TBlobField;
Label1: TLabel;
DBEdit1: TDBEdit;
Label2: TLabel;
DBEdit2: TDBEdit;
procedure Image1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure DataSource1DataChange(Send er: TObject; Field: TField);
procedure FormDestroy(Sender: TObject);
private
PicPath : string;
procedure LoadPic;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses Jpeg;
procedure TForm1.Image1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Image1.Picture.LoadFromFil e( OpenDialog1.FileName);
PicPath := OpenDialog1.FileName;
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
Table1.Append;
Image1.Enabled := True;
Image1.Picture.Assign(Nil) ;
end;
procedure TForm1.Button2Click(Sender : TObject);
begin
Table1Pic.LoadFromFile(Pic Path);
Table1.Post;
Image1.Enabled := False;
end;
procedure TForm1.DataSource1DataChan ge(Sender: TObject; Field: TField);
begin
LoadPic;
end;
procedure TForm1.LoadPic;
begin
if Table1.State = dsBrowse then
begin
Table1Pic.SaveToFile('Tmp. jpg');
Image1.Picture.LoadFromFil e('Tmp.jpg ');
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if fileExists('Tmp.jpg') then
DeleteFile('Tmp.jpg');
end;
give me your email and i will send the project to you
Best regards
Mohammed Nasman
I didn't get ur email, anyway here's the sample
the table Structure
PicId : No
PicDesc : Text
Pic : Blob
add image component and link the first two fields with the DBEdit boxes and add image component, cuz DBImage doesn't support the jpeg format
also add open dialog, two buttns and dbgrid
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, DBCtrls, Db, DBTables, Grids, DBGrids, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
Table1PicID: TFloatField;
Table1PicDesc: TStringField;
Table1Pic: TBlobField;
Label1: TLabel;
DBEdit1: TDBEdit;
Label2: TLabel;
DBEdit2: TDBEdit;
procedure Image1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure DataSource1DataChange(Send
procedure FormDestroy(Sender: TObject);
private
PicPath : string;
procedure LoadPic;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses Jpeg;
procedure TForm1.Image1Click(Sender:
begin
if OpenDialog1.Execute then
begin
Image1.Picture.LoadFromFil
PicPath := OpenDialog1.FileName;
end;
end;
procedure TForm1.Button1Click(Sender
begin
Table1.Append;
Image1.Enabled := True;
Image1.Picture.Assign(Nil)
end;
procedure TForm1.Button2Click(Sender
begin
Table1Pic.LoadFromFile(Pic
Table1.Post;
Image1.Enabled := False;
end;
procedure TForm1.DataSource1DataChan
begin
LoadPic;
end;
procedure TForm1.LoadPic;
begin
if Table1.State = dsBrowse then
begin
Table1Pic.SaveToFile('Tmp.
Image1.Picture.LoadFromFil
end;
end;
procedure TForm1.FormDestroy(Sender:
begin
if fileExists('Tmp.jpg') then
DeleteFile('Tmp.jpg');
end;
give me your email and i will send the project to you
Best regards
Mohammed Nasman
just to remember to read my comments above :-)
I'm always using Blob field to store the images with paradox and other databases :)
? i've nothing other expected
ASKER
Hi, I really appreciate your help, but I have to leave for a trip now. I will evaluate your comments as soon I will be back. (12 days)
Best regards, CC.
Best regards, CC.
ASKER
Hi Experts,
I'm sorry, but I've forgotten to close this Q.
The code that actually helped me was provided by MrGhost.
Thanx to all of U for your help.
Regards, CC
I'm sorry, but I've forgotten to close this Q.
The code that actually helped me was provided by MrGhost.
Thanx to all of U for your help.
Regards, CC
? the answer just do not answer the initial q,
it just converts a jpg-file to a bitmap-file,
in a complex way
and
this can be done simpler
a bit disapointed
meikl ;-)
it just converts a jpg-file to a bitmap-file,
in a complex way
and
this can be done simpler
a bit disapointed
meikl ;-)
I made a sample for that, give me your email and i will send it to you, or send me email at nasman@mogaza.org