數據庫table定義
create table test(image image)
delphi程序
ADOQuery1的sql為'select * from test'
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,JPEG,StdCtrls, Buttons, ExtCtrls, DB, ADODB;
type
TForm1 = class(TForm)
Image1: TImage;
BitBtn1: TBitBtn;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery1image: TBlobField;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
jpeg:TJpegImage;
mem:TmemoryStream;
begin
mem:=TmemoryStream.Create;
mem.LoadFromFile('E:AdobeAdobe1.jpg');
ADOQuery1.Insert;
TBlobField(ADOQuery1.FieldByName('Image')).LoadFromStream(mem);
ADOQuery1.Post;
mem.Free;
ADOQuery1.First;
jpeg:=TJpegImage.Create;
TBlobField(ADOQuery1.FieldByName('image')).SaveToFile('E:aa.jpg');
jpeg.LoadFromFile('E:aa.jpg');
Image1.Picture.Assign(jpeg);
jpeg.Free;
deleteFile('E:aa.jpg');
end;
end.
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/) 一定要Use JPEG!!!!
通过这个方法,任何可被操作系统识别的文件,都可以载入载出到数据库。