如何将ACCESS的OLE对象字段存储的BMP图象显示出来
在ACCESS表中将BMP图象通过插入对象的方式存储于OLE对象字段,现在的问题是如何将图象显示出来,我用的是ADO。谢谢
// 显示图象函数 // 返回值表示图象显示是否成功 // 显示图象函数,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;
[此贴子已经被作者于2005-9-7 15:03:16编辑过]
// 显示图象函数 // 返回值表示图象显示是否成功 // 显示图象函数,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;