DELPHI存取JPEG、BMP图像到数据库完整解决方案计算机等级考试

文章作者 100test 发表时间 2009:06:24 19:07:42
来源 100Test.Com百考试题网


  2009年下半年全国计算机二级考试报名时间从6月1日起已经开始报名。详情点击:2009年下半年全国计算机等级考试各地报名点汇总。2009年下半年全国计算机二级考试时间是2009年9月19日至23日。更多优质资料尽在百考试题论坛 百考试题在线题库

  {==============================
  DELPHI存取JPEG、BMP图像到数据库完整解决方案(演示版)
  版权所有  李明亮 2003-2008
  成都地区的朋友需要我兼职的话,请联系。
  [email protected]
  ===============================}
  unit Unit1.
  interface
  uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ExtDlgs, StdCtrls, ADODB, Grids, DBGrids, ExtCtrls,jpeg,
  DBCtrls.
  type
  TForm1 = class(TForm)
  DBGrid1: TDBGrid.
  ADOConnection1: TADOConnection.
  ADOTable1: TADOTable.
  0selectimage: 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.
  Label3: TLabel.
  Label4: TLabel.
  DBImage1: TDBImage.
  procedure 0selectimageClick(Sender: TObject).
  procedure savetodbClick(Sender: TObject).
  procedure ADOTable1AfterScroll(DataSet: TDataSet).
  procedure savetofileClick(Sender: TObject).
  procedure Button1Click(Sender: TObject).
  procedure FormCreate(Sender: TObject).
  procedure ADOTable1BeforeScroll(DataSet: TDataSet).
  private
  { Private declarations }
  public
  { Public declarations }
  end.
  var
  Form1: TForm1.
  implementation
  uses unit2.
  {$R *.dfm}
  procedure TForm1.0selectimageClick(Sender: TObject). //选择图像
  begin
  if openpicturedialog1.Execute then
  image1.Picture.LoadFromFile(openpicturedialog1.FileName ).
  end.
  ////如下保存方法only to sql and access\data
  procedure TForm1.savetodbClick(Sender: TObject). //保存图像
  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.
  DBImage1.dataField :=\\. //dbimage只能显示BMP,否则myimage由BMP变为jpeg时会出错
  tblobfield(adotable1.FieldByName(\myimage\)).LoadFromStream(strm).
  //如需直接由文件保存 TBlobField(adotable1.FieldByName(\myimage\)).LoadFromFile(OpenPictureDialog1.FileName).
  //以下记录保存到数据库的图像格式
  if uppercase(ext) = \.BMP\ then
  begin
  adotable1.FieldByName(\isbmp\).Value := 1.
  dbimage1.dataField := \myimage\.
  end
  else if (uppercase(ext) = \.JPG\) OR ( uppercase(ext) = \.JPEG\) THEN
  adotable1.FieldByName(\isbmp\).Value := 0.
  adotable1.Post .
  finally
  strm.Free . //如果你选用TBLOBSTREAM类,程序运行到此语句会出错,可该语句前添入adotable1.edit
  end.
  end.
  end.

相关文章


DELPHI存取JPEG、BMP图像到数据库完整解决方案计算机等级考试
Delphi与SQLServer存储过程编程详解计算机等级考试
Delphi的Query控件计算机等级考试
delphi调用sqlserver2000存储过程计算机等级考试
Delphi开发单机瘦数据库程序要点计算机等级考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛