直接显示到DBGRID中是不可能的,你只能通过点击DBGRID 中这个BLOB字段的时候在适当的位置弹出一个窗口显示该图片
如:
1.datasource、datatable、dbgrid之间的关联
2.创建一窗体用image专门显示表中的blob
// 显示图象函数
// 返回值表示图象显示是否成功
// 显示图象函数,pictype 可为:'BMP' 'JPG' 'JPEG'function ViewPicture(img:TImage; query:TADOQuery; fieldname:String; pictype:String):boolean;
var
jpg : TJpegImage;
ts : TStream;
gif : TGifImage;
begin
result := false;
pictype := LowerCase(pictype);
try
ts := query.CreateBlobStream(query.FieldByName(fieldname),bmRead);
if ts.Size=0 then exit;
if (pictype='bmp') or (pictype='image/bmp') then
begin
try
img.Picture.Bitmap.LoadFromStream(ts);
result := true;
except
end;
end;
if (pictype='jpg') or (pictype='image/pjpeg') then
begin
jpg := TJpegImage.Create;
try
jpg.LoadFromStream(ts);
img.Picture.Bitmap.Assign(jpg);
result:=true;
finally
jpg.Free;
end;
end;
if (pictype='gif') or (pictype='image/gif') then
begin
gif := TGifImage.Create;
try
gif.LoadFromStream(ts);
img.Picture.Bitmap.Assign(gif);
result:=true;
finally
gif.Free;
end;
end;
ts.Free;
except end;
end;
3.设计点击DBGRID列标志时弹出显示图片窗口