Delphi有一些数据库显示图片的控件,与数据库一起操作时,为什么只能存取*.bmp格式的图片,而不能对*.bmp以外的格式进行存取呢.谁有这方面经验的,请各位帮帮忙.我现在用一个Developer Express Inc提供的一图片控件(TdxDBGraphicEdit),,但好像只能存取bmp格式的图片,要存取*.jpg或*.gif格式图片到数据库中,该怎么做呢!!!!!求命啊~~~ ~~~~~ `~~~~~~````~~~~~~~~~```~~~~~~~```~~~~~
调试欢乐多
uses
jpeg
之后就可以操作jpg图片了
procedure TForm1.Button1Click(Sender: TObject);
var
Ms:TmemoryStream;
jpg:Tjpegimage;begin
if (OpenPictureDialog1.Execute) and (edit1.Text<>'') then
begin
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName); ms:=TmemoryStream.Create;
Jpg:=TJpegImage.Create;
Jpg.Assign(Image1.Picture.Graphic);//转为jpeg格式
Jpg.SaveToStream(Ms) ;
Ms.Position :=0; adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('insert picture(pic_name,picture) values(:pic_name,:picture)'); //保存图片到数据库
adoquery1.Parameters.ParamByName('pic_name').Value := edit1.Text;
adoQuery1.Parameters.ParamByName('picture').LoadFromStream(ms,ftBlob);
adoquery1.ExecSQL; Ms.Free ;
jpg.free;
end
else
begin
showmessage('保存出错或无文件名!');
exit;
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var ms:TMemoryStream;
jpgshow:TJPEGImage;
begin
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from picture');
adoquery2.Open;
Label1.Caption := ADOQuery2.FieldValues['pic_name']; if ADOQuery2.FieldValues['picture']=null then
begin
showmessage('没图片!');
exit;
end;
ms:=TMemoryStream.Create;
Jpgshow:=TJPEGImage.Create;
TBlobField(ADOquery2.FieldByName('picture')).SaveToStream(ms);//从数据库调出图片并显示
ms.Position :=0;
Jpgshow.LoadFromStream(ms);
Image2.Picture.Assign(Jpgshow);
ms.Free;
jpgshow.free;
end;
对于gif的图片,存储的方法一样,显示时需要装个gif的控件就好。
在cxDBImage的Properties.GraphicClassName中设定.
DevExpress Dx开头的控件都差不多淘汰了.
begin
// defaultext:='jpg';
filter:='*.jpg,*.tif,*.bmp,*.png';
if od2.execute then
begin
bmp1:=TBitmap.Create;
jpg1:=TJpegImage.Create;
try
jpg1.LoadFromFile(od2.FileName);
bmp1.Assign(jpg1);
adoquery1.Edit;
adoquery1.FieldByName('tupian').Assign(bmp1);
adoquery1.fieldbyname('name').AsString:=dbedit15.Text;
adoquery1.post;
finally
jpg1.Free;
bmp1.Free;
end; dbedit15.Text:=od2.FileName;
end;
end;
点击选择图片按钮的同时保存了选择的图片
od2是opendialog
我只会这一种呢
我也是用这种方法存取图片的