//保存的过程 procedure Tscyx.BitBtn26Click(Sender: TObject); var bitmap:Tbitmap; jpg:Tjpegimage; desk:tcanvas; MS_JpegStream:TMemoryStream; ss:string; begin bitmap:=tbitmap.Create; jpg:=tjpegimage.Create; desk:=tcanvas.Create; desk.Handle:=getdc(Panel7.Handle); with bitmap do begin pixelformat:=pf1bit; width:=panel7.Width; height:=panel7.Height; canvas.CopyRect(canvas.cliprect,desk,desk.cliprect); end; jpg.Assign(bitmap); try MS_JpegStream:=TMemoryStream.Create; jpg.SaveToStream(MS_JpegStream); MS_JpegStream.Position:=0; if ClientDataSet1.Active then ClientDataSet1.Close; ClientDataSet1.CommandText:='update xiujing set tp=:x1 where jh='''+'12-21'+''''; ClientDataSet1.Params.ParamByName('x1').LoadFromStream(MS_JpegStream,ftblob); ClientDataSet1.Execute; finally MS_JpegStream.Free; Bitmap.Free; jpg.free; end; end;//调用 procedure Tscyx.BitBtn28Click(Sender: TObject); var bitmap:Tbitmap; jpg:Tjpegimage; JpegStream:TMemoryStream; ss:string; begin JpegStream:=TMemoryStream.Create; if ClientDataSet1.Active then ClientDataSet1.Close; ClientDataSet1.CommandText:='select tp from xiujing where jh='''+'12-21'+''''; ClientDataSet1.Open; if ClientDataSet1.FieldByName('tp').isnull then image4.Picture.Graphic:=nil else begin (ClientDataSet1.FieldByName('tp') as tblobfield).savetostream(JpegStream); image4.Picture.Graphic:=nil; image4.Picture.Graphic:=TJpegImage.Create; JpegStream.Position:=0; image4.Picture.Graphic.LoadFromStream(JpegStream); end; JpegStream.Free; end;保存时不提示错误,但是发现存入库中的只有4个字节。调用时,每次都在“(ClientDataSet1.FieldByName('tp') as tblobfield).savetostream(JpegStream);”这里出错“Access violation at address 098F6699 in module 'SCYXPR~1.OCX'. Read of address 0000000D.”,但是确定后,程序仍然可以执行,如果库中有正确的图片,也可以调出来。我用的是客户端Activform方式,使用了soapconnection连接中间层。
procedure Tscyx.BitBtn26Click(Sender: TObject);
var
bitmap:Tbitmap;
jpg:Tjpegimage;
desk:tcanvas;
MS_JpegStream:TMemoryStream;
ss:string;
begin
bitmap:=tbitmap.Create;
jpg:=tjpegimage.Create;
desk:=tcanvas.Create;
desk.Handle:=getdc(Panel7.Handle); with bitmap do
begin
pixelformat:=pf1bit;
width:=panel7.Width;
height:=panel7.Height;
canvas.CopyRect(canvas.cliprect,desk,desk.cliprect);
end;
jpg.Assign(bitmap);
try
MS_JpegStream:=TMemoryStream.Create;
jpg.SaveToStream(MS_JpegStream);
MS_JpegStream.Position:=0; if ClientDataSet1.Active then ClientDataSet1.Close;
ClientDataSet1.CommandText:='update xiujing set tp=:x1 where jh='''+'12-21'+'''';
ClientDataSet1.Params.ParamByName('x1').LoadFromStream(MS_JpegStream,ftblob);
ClientDataSet1.Execute;
finally
MS_JpegStream.Free;
Bitmap.Free;
jpg.free;
end;
end;//调用
procedure Tscyx.BitBtn28Click(Sender: TObject);
var
bitmap:Tbitmap;
jpg:Tjpegimage;
JpegStream:TMemoryStream;
ss:string;
begin JpegStream:=TMemoryStream.Create; if ClientDataSet1.Active then ClientDataSet1.Close;
ClientDataSet1.CommandText:='select tp from xiujing where jh='''+'12-21'+'''';
ClientDataSet1.Open; if ClientDataSet1.FieldByName('tp').isnull then
image4.Picture.Graphic:=nil
else
begin
(ClientDataSet1.FieldByName('tp') as tblobfield).savetostream(JpegStream);
image4.Picture.Graphic:=nil;
image4.Picture.Graphic:=TJpegImage.Create;
JpegStream.Position:=0;
image4.Picture.Graphic.LoadFromStream(JpegStream);
end;
JpegStream.Free;
end;保存时不提示错误,但是发现存入库中的只有4个字节。调用时,每次都在“(ClientDataSet1.FieldByName('tp') as tblobfield).savetostream(JpegStream);”这里出错“Access violation at address 098F6699 in module 'SCYXPR~1.OCX'. Read of address 0000000D.”,但是确定后,程序仍然可以执行,如果库中有正确的图片,也可以调出来。我用的是客户端Activform方式,使用了soapconnection连接中间层。