用流来读,分析其头部信息来判断:
//显示
procedure TForm1.Button1Click(Sender: TObject);
var
aBitmap: TBitmap;
aJPEGImage: TJPEGImage;
aStream: TStream;
head: word;
const
bmp = $4D42;
jpeg = $D8FF;
begin
aBitmap:= TBitmap.Create;
aJPEGImage:= TJPEGImage.Create;
aStream:= TMemoryStream.Create;
try
TBlobField(ADOQuery1.FieldByName('pic')).SaveToStream(aStream);
aStream.Position := 0; //一定要有这句
aStream.Read(head,2);
aStream.Position:= 0;
if head = bmp then
begin
aBitmap.LoadFromStream(aStream);
Image1.Picture.Assign(aBitmap);
end
else if head = jpeg then
begin
aJPEGImage.LoadFromStream(aStream);
Image1.Picture.Assign(aJPEGImage);
end;
finally
aBitmap.Free;
aJPEGImage.Free;
aStream.Free;
end;
end;