给你一个自己作的,现在正在使用,经过实践考验的,你应该能从里面提取出来你需要的东西.希望对你有帮助.
存:
procedure TFrmYGK.BitBtn1Click(Sender: TObject);
var
strm: TMemoryStream;
STRSQL: String;
str:string;
begin
OPD1.Filter:='*.jpg|*.jpg|*.jpeg|*.jpeg';
WITH ADOqryall do
begin
close;
sql.Clear;
sql.Add('select * from 客户 where 客户编号='''+ADOqrytg.fieldbyname('客户名').AsString+'''');
open;
end;
OPD1.InitialDir:='f:/图稿/'+''+ADOqryall.FieldByName('公司名称').AsString+'';
if OPD1.Execute then
begin
Image1.Picture.LoadFromFile(OPD1.FileName );
strm := tmemorystream.Create ;
strsql:='update 图稿库 set 图稿=:a ,BS=:b where id='''+adoqrytg.fieldbyname('id').AsString+''';';
str:=adoqrytg.fieldbyname('id').AsString;
with adoqryall do
begin
close;
sql.Clear;
sql.Text:=strsql;
end;
try
image1.Picture.Graphic.SaveToStream(strm);
adoQrytg.Edit ;
strm.Position :=0;
adoqryall.Parameters[0].LoadFromFile(OPD1.FileName,ftGraphic);
adoqryall.Parameters[1].Value:=1;
adoqryall.ExecSQL;
adoqrytg.Close;
adoqrytg.Open;
adoqrytg.Locate('id',str,[loCaseInsensitive]);
finally
strm.Free;
end;
end;
end;
取
为了能完全显示图片.我把读出的图片放到image控件中了)
procedure TFrmYGK.ADOQrytgAfterScroll(DataSet: TDataSet);
var
strm: TADOBlobStream;
bl,bl1:double;
begin
strlx1:=adoqrytg.fieldbyname('标类型').AsString;
if adoqrytg.FieldByName('BS').AsInteger =1 then
begin
{ with adoqryall2 do
begin
close;
sql.Clear;
sql.Add('select 图稿 from 图稿库 where id='''+adoqrytg.fieldbyname('ID').AsString+'''');
OPEN;
end; }
strm := tadoblobstream.Create(tblobfield(adoqrytg.fieldbyname('图稿')),bmread);
//strm := tadoblobstream.Create(tblobfield(adoqryALL2.fieldbyname('图稿')),bmread);
try // try1
strm.position :=0;
image1.Picture.Graphic := nil; //清除图像
jpegimage := tjpegimage.Create ;
try //try12
jpegimage.LoadFromStream(strm);
image1.Picture.Graphic := jpegimage;
if RadioButton2.Checked=true then
begin
image1.Height:=image1.Picture.Height;
image1.Width:=image1.Picture.Width;
end
else if radiobutton1.Checked=true then
begin
if (image1.Picture.Width>ScrollBox1.Width) and (image1.Picture.Height>ScrollBox1.Height) then
begin
bl:=image1.Picture.Width/ScrollBox1.Width;
bl1:=image1.Picture.Height/scrollbox1.Height;
if bl<bl1 then
begin
image1.Height:=scrollbox1.Height;
image1.Width:=floor(image1.Picture.Width/bl1);
end
else
begin
image1.Width:=scrollbox1.Width;
image1.Height:=floor(image1.Picture.Height/bl);
end;
end
else if (image1.Picture.Width>ScrollBox1.Width) and (image1.Picture.Height<=ScrollBox1.Height) then
begin
bl:=image1.Picture.width/scrollbox1.Width;
image1.Width:=scrollbox1.Width;
image1.Height:=floor(image1.Picture.Height/bl);
end
else if (image1.Picture.Width<=ScrollBox1.Width) and (image1.Picture.Height>ScrollBox1.Height) then
begin
bl:=image1.Picture.height/scrollbox1.height;
image1.height:=scrollbox1.height;
image1.width:=floor(image1.Picture.width/bl);
end
else
begin
image1.Height:=image1.Picture.Height;
image1.Width:=image1.Picture.Width;
end;
end
else if radiobutton3.Checked=true then
begin
image1.Align:=alclient;
image1.Stretch:=true;
end;
intheight:=jpegimage.Height;
intwidth:=jpegimage.Width;
finally
jpegimage.Free ;
end; //end try12
finally
strm.Free ;
end; //end try1
end
else
begin
image1.Picture.Graphic:=nil;
end;
image1.Stretch:=true;
end;