数据库:sql server2000
字段:照片 image
如何将图片存入数据库中,并在Delphi中显示出来,我在我的窗体中有组件Timage,如何在其中显示啊、?
字段:照片 image
如何将图片存入数据库中,并在Delphi中显示出来,我在我的窗体中有组件Timage,如何在其中显示啊、?
解决方案 »
- 关于多个Excel之间复制的问题
- 请高手 调试一个 小问题 不胜感激
- 如何知道当前所在的目录?全部家当只求一解!
- ***************能否用代码读取U盘序列号**************
- ActiveX控件正常下载后,我将.ocx和其他.dll文件自动下载到C:\winnt目录下,为何通过.ocx调用时提示找不到.dll呢
- “superyys(无血野人)”与“laughcsdn (笑傲中国软件) ”是同一人
- Delphi 6-->ScrollBox
- delphi中有沒有像vb中的new collection的類型
- 请问如何查阅帮助?
- 请教大侠:为什么用TABLE.LOCATE来定位会出现该记录后面的记录不能显示?怎样避免?
- 如何利用IdFTP控件获取FTP服务器端某个子文件目录中的文件列表
- 各位高手指点一下关于paintbox的画面显示问题!
var
strm:tmemorystream;
ext:string;
begin
if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
begin
ext:=extractfileext(openpicturedialog1.FileName ); //取出文件的扩展名
strm := tmemorystream.Create ;
try
image1.Picture.Graphic.SaveToStream(strm);
adotable1.Edit ;
strm.Position :=0;
tblobfield(adotable1.FieldByName('myimage')).LoadFromStream(strm);
//如需直接由文件保存可采用如下注释行
//TBlobField(adotable1.FieldByName('myimage')).LoadFromFile(OpenPictureDialog1.FileName);
//以下记录保存到数据库的图像格式
if uppercase(ext) = '.BMP' then
adotable1.FieldByName('isbmp').Value := 1 //BMP型图像数据
else if (uppercase(ext) = '.JPG') OR ( uppercase(ext) = '.JPEG') Then
adotable1.FieldByName('isbmp').Value := 0; //JPEG型图像数据
adotable1.Post ;
finally
strm.Free ; //如strm采用tblobstream类,程序运行到该语句会出现问题
end;
end;
end;
var
strm:tadoblobstream;
jpegimage:tjpegimage;
bitmap:tbitmap;
begin
strm := tadoblobstream.Create(tblobfield(adotable1.fieldbyname('MYIMAGE')),bmread);
try //try1
strm.position :=0;
image1.Picture.Graphic := nil; //清除图像
// BMP、JPEG两种图像数据必需分别处理
if adotable1.fieldbyname('isbmp').asstring ='1' then //BMP型图像数据
begin //begin11
bitmap := tbitmap.Create ;
try //try11
bitmap.LoadFromStream(strm);
image1.Picture.Graphic := bitmap;
finally
bitmap.Free;
end; //end try11
end //end begin11
else if adotable1.fieldbyname('isbmp').asstring ='0' then //JPEG型图像数据
begin //begin12
jpegimage := tjpegimage.Create ;
try //try12
jpegimage.LoadFromStream(strm);
image1.Picture.Graphic := jpegimage;
finally
jpegimage.Free ;
end; //end try12
end; //end begin12
finally
strm.Free ;
end; //end try1
end;