给你一断我的代码,不过你要有TMySQL.Components for Delphi控件,
URL: http://www.inprises.com/control/TMySQL.Components.v2001.1.0.0.For.Delphi.And.Kylix.Incl.Full.Source-DiSTiNCT.rar
====================================================================
{本程序已实现了图像从mysql数据库存入和读出
作者:刘志强
image表:
code char 10
image longblob (*如换成blob则存储很慢)
}
unit Unit119;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, MySQLDataset, Grids, DBGrids, MySQLServer, StdCtrls, DBCtrls;type
TForm1 = class(TForm)
MySQLServer1: TMySQLServer;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
MySQLQuery1: TMySQLQuery;
Button1: TButton;
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);
var
Buffer: PChar;
fd: Integer;
Stream: TMySQLBlobStream;
bmp:TBitmap;
flen:Int64;
begin
bmp:=TBitmap.Create;
try
//向Mysql表写入Bmp图像
bmp.LoadFromFile('c:\program files\common files\borland shared\Images\Splash\256color\factory.bmp');
MySQLQuery1.Open;
MySQLQuery1.Append;
MySQLQuery1.FieldByName('code').AsString:='刘志12';
MySQLQuery1.FieldbyName('image').Assign(bmp);
MySQLQuery1.TableName:='image';
MySQLQuery1.post;
//从Mysql表读出Bmp图像
MySQLQuery1.close;
MySQLQuery1.SQl.Clear;
MySQLQuery1.SQL.Add('select * from image where code="刘志12"');
MySQLQuery1.Open; MySQLQuery1.Next;
MySQLQuery1.Edit;
Stream := TMySQLBlobStream.Create(MySQLQuery1.FieldByName('Image') as TBlobField, bmReadWrite);
bmp.LoadFromStream(stream);
canvas.Draw(0,0,bmp);
finally
Stream.Free;
bmp.Free;
end; end;procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
bmp:TBitmap;
stream:TMySQLBlobStream;
beginend;end.
URL: http://www.inprises.com/control/TMySQL.Components.v2001.1.0.0.For.Delphi.And.Kylix.Incl.Full.Source-DiSTiNCT.rar
====================================================================
{本程序已实现了图像从mysql数据库存入和读出
作者:刘志强
image表:
code char 10
image longblob (*如换成blob则存储很慢)
}
unit Unit119;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, MySQLDataset, Grids, DBGrids, MySQLServer, StdCtrls, DBCtrls;type
TForm1 = class(TForm)
MySQLServer1: TMySQLServer;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
MySQLQuery1: TMySQLQuery;
Button1: TButton;
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);
var
Buffer: PChar;
fd: Integer;
Stream: TMySQLBlobStream;
bmp:TBitmap;
flen:Int64;
begin
bmp:=TBitmap.Create;
try
//向Mysql表写入Bmp图像
bmp.LoadFromFile('c:\program files\common files\borland shared\Images\Splash\256color\factory.bmp');
MySQLQuery1.Open;
MySQLQuery1.Append;
MySQLQuery1.FieldByName('code').AsString:='刘志12';
MySQLQuery1.FieldbyName('image').Assign(bmp);
MySQLQuery1.TableName:='image';
MySQLQuery1.post;
//从Mysql表读出Bmp图像
MySQLQuery1.close;
MySQLQuery1.SQl.Clear;
MySQLQuery1.SQL.Add('select * from image where code="刘志12"');
MySQLQuery1.Open; MySQLQuery1.Next;
MySQLQuery1.Edit;
Stream := TMySQLBlobStream.Create(MySQLQuery1.FieldByName('Image') as TBlobField, bmReadWrite);
bmp.LoadFromStream(stream);
canvas.Draw(0,0,bmp);
finally
Stream.Free;
bmp.Free;
end; end;procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
bmp:TBitmap;
stream:TMySQLBlobStream;
beginend;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货