仔细看看我的代码,理解了就OK了,谁说DELPHI不支持JPG,现在的年轻人真感唠
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
t1 : TTable;
mstream1 : TMemoryStream;
// jpeg : TJPEGImage;
begin
// jpeg := TJPEGImage.Create ;
t1 := TTable.Create(nil);
t1.DatabaseName := db1.DatabaseName ;
t1.TableName := 'T_BASE';
t1.Open;
t1.First ;
while not t1.Eof do
begin
if t1.FieldByName('id').AsInteger = nCurrentRec then
begin
mstream1 := TMemoryStream.Create;
// TBlobField(t1.FieldByName('image')).SaveToFile('c:/temp.bmp');
// imageBase.Picture.Bitmap.LoadFromFile('c:/temp.bmp');
TBlobField(t1.FieldByName('image')).SaveToStream(mstream1) ;
mstream1.Position := 0;
// TBlobField(t1.FieldByName('image')).SaveToFile ('c:/2.jpg');
// imageBase.Picture.LoadFromFile('c:/2.jpg');
imageBase.Picture.Bitmap.LoadFromStream(mstream1);//bmp文件
// jpeg.LoadFromStream(mstream1);//JPEG文件
// imageBase.Picture.Assign(jpeg);
// imageBase.Picture.Bitmap.SaveToFile('c:/temp.bmp');
{ if OpenDialog1.Execute then
begin
if FileExists(OpenDialog1.FileName) then
begin
imageBase.Picture.LoadFromFile(OpenDialog1.FileName);
end;
end;}
imageBase.AutoSize := true;
DBGrid1.Visible := false;
imageBase.Show ;
imageBase.OnClick := imageBaseClick;
mstream1.Free ;
end;
t1.Next;
end;
t1.Close;
t1.Free;
end;