var
ms:tmemorystream;
jp:TJpegImage;
begin
jp.Assign(Image1.Picture.Bitmap);
ms:=tmemorystream.Create;
jp:=TJpegImage.Create;
ms.Position:=0;
jp.SaveToStream(ms);
try
with ADOQuery1 do
begin
Open;
Insert;
TBlobField(FieldByName('i')).LoadFromStream(ms);
Close;
end;
finally
ms.Free;
jp.Free;
end;
end;
var oPic :TPicture;
oBitmap :TBitmap;
oStream :TMemoryStream;
Size :integer;
begin
oPic := TPicture.Create;
oBitmap := TBitmap.Create;
oStream := TMemoryStream.Create();
try
with oData do
begin
DisableControls;
First;
while not Eof do
begin
sF :=PathQryPhotopath.Value+oData.FieldByName('Bz2').AsString;
if oData.FieldByName('Photo').IsNull then
if FileExists(sF) then
begin
oPic.Graphic := nil;
oPic.LoadFromFile( sF);
oBitmap.Width := oPic.Width;
oBitmap.Height := oPic.Height;
oBitmap.Canvas.Draw(0,0, oPic.Graphic);
oBitmap.SaveToStream(oStream);
Edit;
oStream.Position := 0;
//以下是核心代码
with oData.CreateBlobStream(FieldByName('Photo'), bmWrite) do
try
CopyFrom(oStream, 0);
finally
Free;
end;