14 个解决方案
#1
高手去那里啦!
#2
快点帮帮忙啦!高手们!先谢谢啦!
#3
兄弟有个建议,可不把图的路径存到数据库中呢!!
#4
unit Unit20;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ExtDlgs, StdCtrls, ExtCtrls, Jpeg;
type
TForm20 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
ADOQuery1: TADOQuery;
ADOQuery1dutycard: TStringField;
ADOQuery1b: TBlobField;
Panel1: TPanel;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Image1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form20: TForm20;
implementation
uses Unit2, Unit4;
{$R *.dfm}
function JpegStartsInBlob(PicField:TBlobField):integer;
var
ghy: TADOBlobstream;
buffer:Word;
hx: string;
begin
Result := -1;
ghy := TADOBlobstream.Create(PicField, bmRead);
try
while (Result = -1) and (ghy.Position + 1 < ghy.Size) do
begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := ghy.Position - 2
else if hx = 'FF' then
ghy.Position := ghy.Position-1;
end;
end;
finally
ghy.Free
end;
end;
procedure TForm20.FormActivate(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tjpegimage;
begin
if adoquery1.RecordCount>0 then
begin
ghy := TADOBlobstream.Create(Adoquery1b, bmRead);
try
ghy.Seek(JpegStartsInBlob(Adoquery1b),soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(ghy);
Image1.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
ghy.Free
end;
button2.Enabled:=true;
end
else
button2.Enabled:=false;
end;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ExtDlgs, StdCtrls, ExtCtrls, Jpeg;
type
TForm20 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
ADOQuery1: TADOQuery;
ADOQuery1dutycard: TStringField;
ADOQuery1b: TBlobField;
Panel1: TPanel;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Image1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form20: TForm20;
implementation
uses Unit2, Unit4;
{$R *.dfm}
function JpegStartsInBlob(PicField:TBlobField):integer;
var
ghy: TADOBlobstream;
buffer:Word;
hx: string;
begin
Result := -1;
ghy := TADOBlobstream.Create(PicField, bmRead);
try
while (Result = -1) and (ghy.Position + 1 < ghy.Size) do
begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := ghy.Position - 2
else if hx = 'FF' then
ghy.Position := ghy.Position-1;
end;
end;
finally
ghy.Free
end;
end;
procedure TForm20.FormActivate(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tjpegimage;
begin
if adoquery1.RecordCount>0 then
begin
ghy := TADOBlobstream.Create(Adoquery1b, bmRead);
try
ghy.Seek(JpegStartsInBlob(Adoquery1b),soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(ghy);
Image1.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
ghy.Free
end;
button2.Enabled:=true;
end
else
button2.Enabled:=false;
end;
#5
SQL里用Blob字段,显示时需要使用Automation Document 技术,你的程序作为Container,调用AutoCAD等的ActiveX组件.(象Word中打开CAD图一样)
#6
procedure getjpg(Sender: TObject);
begin
adoquery1.close;
adoquery1.sql.text := 'select id, img from table1';
adoquery1.open;
TBlobfield(adoquery1.fieldbyname('img')).savetofile('c:\test.jpg');
image1.loadfromfile('c:\test.jpg');
end;
begin
adoquery1.close;
adoquery1.sql.text := 'select id, img from table1';
adoquery1.open;
TBlobfield(adoquery1.fieldbyname('img')).savetofile('c:\test.jpg');
image1.loadfromfile('c:\test.jpg');
end;
#7
cdsgajxlp(起名很难) 代码应该可以
但适用数据库中jpeg图象显示。
但适用数据库中jpeg图象显示。
#8
建议还是存路径吧!
#9
可以的Blob字段操作而已
存
var
CADStream: TFileStream;
begin
CADStream:= TFileStream.Create(...)
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into CADTable values(..,:CAD,..)');
ADOQuery1.Parameters.ParamByName('CAD').LoadFromStream(CADStream, ftBlob);
ADOQuery1.ExecSQL;
....
end;
取
SELECT * FROM CADTable .....
用一个流来保存图片,然后在用控件显示
存
var
CADStream: TFileStream;
begin
CADStream:= TFileStream.Create(...)
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into CADTable values(..,:CAD,..)');
ADOQuery1.Parameters.ParamByName('CAD').LoadFromStream(CADStream, ftBlob);
ADOQuery1.ExecSQL;
....
end;
取
SELECT * FROM CADTable .....
用一个流来保存图片,然后在用控件显示
#10
同意楼上的,先把图片保存到流文件中,然后保存到数据库中,如果是SQL Server可以用Image或者Blob保存.读取的时候用下面代码:
begin
with ADOQuery1 do
Close;
SQL.Clear;
SQL.Add('select * from CADTable');
(fieldbyname('CAD').as TBlobField).SaveToFile('路径名');
Open;
end;
begin
with ADOQuery1 do
Close;
SQL.Clear;
SQL.Add('select * from CADTable');
(fieldbyname('CAD').as TBlobField).SaveToFile('路径名');
Open;
end;
#11
楼主是要显示 jpg,bmp等格式的CAD图,还是dwg(AutoCAD)格式的图?
如果是后者,上面的程序只解决了存取数据库问题,显示不用Automation,那只能编程读取文件格式,自己显示了,太烦了.....
如果是后者,上面的程序只解决了存取数据库问题,显示不用Automation,那只能编程读取文件格式,自己显示了,太烦了.....
#12
谢谢各位啦!可是还是不能动态的显示相应的图纸啊!怎么办啊?
#13
顶一下,还是不能显示啊!
#14
自己顶一下
#1
高手去那里啦!
#2
快点帮帮忙啦!高手们!先谢谢啦!
#3
兄弟有个建议,可不把图的路径存到数据库中呢!!
#4
unit Unit20;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ExtDlgs, StdCtrls, ExtCtrls, Jpeg;
type
TForm20 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
ADOQuery1: TADOQuery;
ADOQuery1dutycard: TStringField;
ADOQuery1b: TBlobField;
Panel1: TPanel;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Image1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form20: TForm20;
implementation
uses Unit2, Unit4;
{$R *.dfm}
function JpegStartsInBlob(PicField:TBlobField):integer;
var
ghy: TADOBlobstream;
buffer:Word;
hx: string;
begin
Result := -1;
ghy := TADOBlobstream.Create(PicField, bmRead);
try
while (Result = -1) and (ghy.Position + 1 < ghy.Size) do
begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := ghy.Position - 2
else if hx = 'FF' then
ghy.Position := ghy.Position-1;
end;
end;
finally
ghy.Free
end;
end;
procedure TForm20.FormActivate(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tjpegimage;
begin
if adoquery1.RecordCount>0 then
begin
ghy := TADOBlobstream.Create(Adoquery1b, bmRead);
try
ghy.Seek(JpegStartsInBlob(Adoquery1b),soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(ghy);
Image1.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
ghy.Free
end;
button2.Enabled:=true;
end
else
button2.Enabled:=false;
end;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ExtDlgs, StdCtrls, ExtCtrls, Jpeg;
type
TForm20 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
ADOQuery1: TADOQuery;
ADOQuery1dutycard: TStringField;
ADOQuery1b: TBlobField;
Panel1: TPanel;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Image1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form20: TForm20;
implementation
uses Unit2, Unit4;
{$R *.dfm}
function JpegStartsInBlob(PicField:TBlobField):integer;
var
ghy: TADOBlobstream;
buffer:Word;
hx: string;
begin
Result := -1;
ghy := TADOBlobstream.Create(PicField, bmRead);
try
while (Result = -1) and (ghy.Position + 1 < ghy.Size) do
begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := ghy.Position - 2
else if hx = 'FF' then
ghy.Position := ghy.Position-1;
end;
end;
finally
ghy.Free
end;
end;
procedure TForm20.FormActivate(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tjpegimage;
begin
if adoquery1.RecordCount>0 then
begin
ghy := TADOBlobstream.Create(Adoquery1b, bmRead);
try
ghy.Seek(JpegStartsInBlob(Adoquery1b),soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(ghy);
Image1.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
ghy.Free
end;
button2.Enabled:=true;
end
else
button2.Enabled:=false;
end;
#5
SQL里用Blob字段,显示时需要使用Automation Document 技术,你的程序作为Container,调用AutoCAD等的ActiveX组件.(象Word中打开CAD图一样)
#6
procedure getjpg(Sender: TObject);
begin
adoquery1.close;
adoquery1.sql.text := 'select id, img from table1';
adoquery1.open;
TBlobfield(adoquery1.fieldbyname('img')).savetofile('c:\test.jpg');
image1.loadfromfile('c:\test.jpg');
end;
begin
adoquery1.close;
adoquery1.sql.text := 'select id, img from table1';
adoquery1.open;
TBlobfield(adoquery1.fieldbyname('img')).savetofile('c:\test.jpg');
image1.loadfromfile('c:\test.jpg');
end;
#7
cdsgajxlp(起名很难) 代码应该可以
但适用数据库中jpeg图象显示。
但适用数据库中jpeg图象显示。
#8
建议还是存路径吧!
#9
可以的Blob字段操作而已
存
var
CADStream: TFileStream;
begin
CADStream:= TFileStream.Create(...)
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into CADTable values(..,:CAD,..)');
ADOQuery1.Parameters.ParamByName('CAD').LoadFromStream(CADStream, ftBlob);
ADOQuery1.ExecSQL;
....
end;
取
SELECT * FROM CADTable .....
用一个流来保存图片,然后在用控件显示
存
var
CADStream: TFileStream;
begin
CADStream:= TFileStream.Create(...)
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into CADTable values(..,:CAD,..)');
ADOQuery1.Parameters.ParamByName('CAD').LoadFromStream(CADStream, ftBlob);
ADOQuery1.ExecSQL;
....
end;
取
SELECT * FROM CADTable .....
用一个流来保存图片,然后在用控件显示
#10
同意楼上的,先把图片保存到流文件中,然后保存到数据库中,如果是SQL Server可以用Image或者Blob保存.读取的时候用下面代码:
begin
with ADOQuery1 do
Close;
SQL.Clear;
SQL.Add('select * from CADTable');
(fieldbyname('CAD').as TBlobField).SaveToFile('路径名');
Open;
end;
begin
with ADOQuery1 do
Close;
SQL.Clear;
SQL.Add('select * from CADTable');
(fieldbyname('CAD').as TBlobField).SaveToFile('路径名');
Open;
end;
#11
楼主是要显示 jpg,bmp等格式的CAD图,还是dwg(AutoCAD)格式的图?
如果是后者,上面的程序只解决了存取数据库问题,显示不用Automation,那只能编程读取文件格式,自己显示了,太烦了.....
如果是后者,上面的程序只解决了存取数据库问题,显示不用Automation,那只能编程读取文件格式,自己显示了,太烦了.....
#12
谢谢各位啦!可是还是不能动态的显示相应的图纸啊!怎么办啊?
#13
顶一下,还是不能显示啊!
#14
自己顶一下