Delphi存取图片

danny2008 2003-11-14 02:20:18

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBXpress, DBCtrls, StdCtrls, DB, DBClient,
Grids, DBGrids,ExtCtrls, ADODB,
jpeg;

type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
Label1: TLabel;
ADOTable1ID: TIntegerField;
ADOTable1files: TBlobField;
ADOTable1filename: TWideStringField;
DBImage1: TDBImage;
DBNavigator1: TDBNavigator;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
ADOTable1.Edit;
ADOTable1files.LoadFromFile(OpenDialog1.FileName);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
JPEGImage:TJPEGImage;
begin
JPEGImage:=TJPEGImage.Create; //创建JPEG图像对象
if OpenDialog1.Execute then
try
JPEGImage.LoadFromFile(OpenDialog1.FileName); //从文件中装载jpg图像,
ADOTable1.Edit;
DBImage1.Picture.Bitmap.Assign(JPEGImage); //将jpg导入
ADOTable1.Post;
finally
JPEGImage.Free; //释放对象
end;
end;

end.
此段代码好用,但是应用的数据库是Access我想问一下在Sql里怎么改阿!!!!!!!!!!
...全文
56 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxreal 2003-11-17
  • 打赏
  • 举报
回复
楼上两位写反了吧
wyr521 2003-11-14
  • 打赏
  • 举报
回复
begin
with ADOQuery1 do
begin
close;
SQL.Text := 'select Image1 from t_1';
Open;
TBlobFile(Fields[0]).LoadFromFile('xxxx.bmp');
Close;
end;
end;

//读取
begin
with ADOQuery1 do
begin
close;
SQL.Text := 'select Image1 from t_1';
Open;
TBlobFile(Fields[0]).SaveToFile('xxxx.bmp');
Close;
end;
end
angle097113 2003-11-14
  • 打赏
  • 举报
回复
//保存
begin
with ADOQuery1 do
begin
close;
SQL.Text := 'select Image1 from t_1';
Open;
TBlobFile(Fields[0]).LoadFromFile('xxxx.bmp');
Close;
end;
end;

//读取
begin
with ADOQuery1 do
begin
close;
SQL.Text := 'select Image1 from t_1';
Open;
TBlobFile(Fields[0]).SaveToFile('xxxx.bmp');
Close;
end;
end;
rockswj 2003-11-14
  • 打赏
  • 举报
回复
用TBolbField一切可以搞定的!

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧