我在DELPHI6(安装了GIFIMAGE)下面编写一个在ACCESS数据库中存取图片的程序,
使用流读取出了图片文件,并且存进了数据库,可是不能存取GIF格式的图片,可是我面临的主要问题就是能够对GIF格式的文件管理,而且最最重要的就是能够从数据库中读出并在IMAGE控件中显示,请各位指教,谢谢!
数据库定义:
ID: 关键字
PICPHOTO: OLE对象DELPHI代码:
//打开图片,并且在IMAGE1中显示
procedure TForm1.Button1Click(Sender: TObject);
var
MS: TFileStream;
begin
if OpenDialog1.Execute then
begin
MS:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
//Image1.Picture.Bitmap.LoadFromStream(MS);
MS.Free;
end;
end;
//存入数据库中
procedure TForm1.btnSaveClick(Sender: TObject);
var
MS: TMemoryStream;
begin
MS:=TMemoryStream.create;
Image1.Picture.Bitmap.SaveToStream(MS);
MS.Position:=0;
AdoTable1.Append;
TBlobField(AdoTable1.FieldbyName('PicPhoto')).LoadFromStream(MS);
AdoTable1.Post;
end;
//从数据库中取出并在IMAGE1中显示
procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
var
MS: TStream;
begin
with AdoTable1 do
MS:=CreateBlobStream(FieldbyName('Picphoto'),bmRead);
Image1.Picture.Graphic.LoadFromStream(MS);
MS.Free;
end;
使用流读取出了图片文件,并且存进了数据库,可是不能存取GIF格式的图片,可是我面临的主要问题就是能够对GIF格式的文件管理,而且最最重要的就是能够从数据库中读出并在IMAGE控件中显示,请各位指教,谢谢!
数据库定义:
ID: 关键字
PICPHOTO: OLE对象DELPHI代码:
//打开图片,并且在IMAGE1中显示
procedure TForm1.Button1Click(Sender: TObject);
var
MS: TFileStream;
begin
if OpenDialog1.Execute then
begin
MS:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
//Image1.Picture.Bitmap.LoadFromStream(MS);
MS.Free;
end;
end;
//存入数据库中
procedure TForm1.btnSaveClick(Sender: TObject);
var
MS: TMemoryStream;
begin
MS:=TMemoryStream.create;
Image1.Picture.Bitmap.SaveToStream(MS);
MS.Position:=0;
AdoTable1.Append;
TBlobField(AdoTable1.FieldbyName('PicPhoto')).LoadFromStream(MS);
AdoTable1.Post;
end;
//从数据库中取出并在IMAGE1中显示
procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
var
MS: TStream;
begin
with AdoTable1 do
MS:=CreateBlobStream(FieldbyName('Picphoto'),bmRead);
Image1.Picture.Graphic.LoadFromStream(MS);
MS.Free;
end;
解决方案 »
- 一段vc程序如何转换成delphi程序
- 我数据库里面的值都是一些整数,我想把这些数在取出时,转成带小数点形式的,怎么转呢
- 界面属性设置问题,菜鸟提问
- 有重复数据时提前提示,我在数据sql内建立了组合索引,就是part_code,st_name 这两个字段不能同时相同,
- 如何动态调整显示器的分辨率
- 如何将Dbmemo植入Dbgrid中
- DBLookupCombox怎样使之达到初始空值状态啊
- delphi
- 俺是初学delphi,现想求一个登陆界面的相关程序。。。高手说说呀
- Grid index out of range错误怎么回事?急急急急!!!
- 谁能发一份关于婚姻登记系统的相关资料及源代码给我(高分相送)。
- 小问题帮忙解决?
估计是图片没有存到数据库。
我把图片存了进去,可是如何读出来呢?下面的是我写的读出的代码:
procedure TForm1.Cjt_JpgLoad;
var
MS: TMemoryStream;
begin
Try
MS := TMemoryStream.Create;
with AdoTable1 do
TBlobField(ADOTable1.FieldByName('Picphoto')).SaveToStream(MS);
//Image1.Picture.LoadFromStream();
MS.Free;
except
Exit;
end;
创建一个内存流,然后将PICPHOTO中的内容写入到MS流中,然后,怎么能把MS流中的内容在IMAGE1中显示出来,这是我急需解决的问题。
var
MS: TMemoryStream;
如果你正确安裝了 gifimage後, 下面代碼應該沒問題吧
begin
Try
MS := TMemoryStream.Create;
with AdoTable1 do
TBlobField(ADOTable1.FieldByName('Picphoto')).SaveToStream(MS);
Ms.Seek(0,soFromBeginning);
Image1.Picture.LoadFromStream(ms);
MS.Free;
except
Exit;
end;