资源描述:
《delphi存取jpeg、bmp图像到数据库完整解决方案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、DELPHI存取JPEG、BMP图像到数据库完整解决方案DELPHI存取JPEG、BMP图像到数据库完整解决方案日期:2006年2月20日作者:李明亮nlh6@sina.com.cn人气:5445查看:[大字体中字体小字体]{=================================================================DELPHI存取JPEG、BMP图像到数据库完整解决方案(演示版)版权所有 李明亮2003-2008成都地区的朋友需要我兼职的话,请联系。nlh6@sina.com.cn==============
2、====================================================}unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,DB,ExtDlgs,StdCtrls,ADODB,Grids,DBGrids,ExtCtrls,jpeg,DBCtrls;typeTForm1=class(TForm)DBGrid1:TDBGrid;ADOConnection1:TADOConnec
3、tion;ADOTable1:TADOTable;selectimage:TButton;savetodb:TButton;OpenPictureDialog1:TOpenPictureDialog;DataSource1:TDataSource;DBNavigator1:TDBNavigator;savetofile:TButton;Label1:TLabel;Label2:TLabel;Button1:TButton;Bevel1:TBevel;Bevel2:TBevel;GroupBox1:TGroupBox;Image1:TImage;La
4、bel3:TLabel;Label4:TLabel;DBImage1:TDBImage;procedureselectimageClick(Sender:TObject);proceduresavetodbClick(Sender:TObject);procedureADOTable1AfterScroll(DataSet:TDataSet);proceduresavetofileClick(Sender:TObject);procedureButton1Click(Sender:TObject);procedureFormCreate(Sende
5、r:TObject);procedureADOTable1BeforeScroll(DataSet:TDataSet);private{Privatedeclarations}public{Publicdeclarations}end;varForm1:TForm1;implementationusesunit2;{$R*.dfm}procedureTForm1.selectimageClick(Sender:TObject);//选择图像beginifopenpicturedialog1.Executethenimage1.Picture.Loa
6、dFromFile(openpicturedialog1.FileName);end;////如下保存方法onlytosqlandaccess'dataprocedureTForm1.savetodbClick(Sender:TObject);//保存图像varstrm:tmemorystream;ext:string;beginifimage1.picture.Graphic<>nilthen//避免image1中无图像保存出错beginext:=extractfileext(openpicturedialog1.FileName);strm:=
7、tmemorystream.Create;tryimage1.Picture.Graphic.SaveToStream(strm);adotable1.Edit;strm.Position:=0;DBImage1.dataField:='';//dbimage只能显示BMP,否则myimage由BMP变为jpeg时会出错tblobfield(adotable1.FieldByName('myimage')).LoadFromStream(strm);//如需直接由文件保存TBlobField(adotable1.FieldByName('myima
8、ge')).LoadFromFile(OpenPictureDialog1.FileName);//以下记录保存到数据库的