unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls,jpeg, Db, ADODB;
type
TForm1 = class(TForm)
Btn_Save: TButton;
Btn_View: TButton;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
Panel1: TPanel;
ViewPic: TImage;
Edit_name: TEdit;
OpenDialog1: TOpenDialog;
Btn_open: TButton;
Btn_next: TButton;
Btn_pre: TButton;
procedure Btn_SaveClick(Sender: TObject);
procedure Btn_ViewClick(Sender: TObject);
procedure Btn_openClick(Sender: TObject);
procedure Btn_nextClick(Sender: TObject);
procedure Btn_preClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Btn_SaveClick(Sender: TObject);
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
MyJPEG := TJPEGImage.Create;
try
with MyJPEG do
begin
Assign(ViewPic.Picture.Graphic);
MS:=TMemoryStream.create;
SaveToStream(MS);
MS.Position:=0;
ADOTable1.Append;
TBlobField(ADOTable1.FieldbyName('file')).LoadFromStream(MS);
ADOTable1.FieldByName('name').AsString:=Edit_Name.Text;
ADOTable1.Post;
Messagebox(Getactivewindow(),'图像保存完毕!','保存',mb_ok);
end;
finally
MyJPEG.Free;
end;
end;
procedure TForm1.Btn_ViewClick(Sender: TObject);
var
tempstream:TStringStream;
tempjpeg:TJPEGImage;
begin
try
tempstream:=TStringStream.Create(' ');
TBlobField(ADOTable1.FieldByName('file')).SaveToStream(tempstream);
tempstream.Position:=0;
tempjpeg:=TJPEGImage.Create;
tempjpeg.LoadFromStream(tempstream);
ViewPic.Picture.Bitmap.Assign(tempjpeg);
Edit_Name.Text:=ADOTable1.FieldByName('name').AsString;
finally
tempstream.Free;
tempjpeg.Free;
end;
end;
procedure TForm1.Btn_openClick(Sender: TObject);
begin
if opendialog1.Execute then
ViewPic.Picture.LoadFromFile(opendialog1.FileName);
end;
procedure TForm1.Btn_nextClick(Sender: TObject);
begin
if not adotable1.Eof then
begin
Btn_ViewClick(nil);
adotable1.Next;
end;
end;
procedure TForm1.Btn_preClick(Sender: TObject);
begin
if not adotable1.Bof then
begin
Btn_ViewClick(nil);
adotable1.MoveBy(-1);
end;
end;
end.
用的是access,ViewPIc is Timage