DBImageru.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:6k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit DBImageru;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   fcImager, Db, DBTables, ComCtrls, ExtCtrls, DBCtrls, fcLabel, DBCGrids,
  6.   StdCtrls,jpeg, ExtDlgs, Mask, Buttons;
  7. type
  8.   TDBImagerDemoForm = class(TForm)
  9.     PageControl1: TPageControl;
  10.     TabSheet1: TTabSheet;
  11.     TabSheet2: TTabSheet;
  12.     TabSheet3: TTabSheet;
  13.     DataSource1: TDataSource;
  14.     Table1: TTable;
  15.     Panel1: TPanel;
  16.     Panel2: TPanel;
  17.     fcLabel5: TfcLabel;
  18.     DBCtrlGrid1: TDBCtrlGrid;
  19.     fcDBImager2: TfcDBImager;
  20.     fcLabel6: TfcLabel;
  21.     MultiImager: TfcDBImager;
  22.     Table2: TTable;
  23.     DataSource2: TDataSource;
  24.     DBNavigator2: TDBNavigator;
  25.     Table1SpeciesNo: TFloatField;
  26.     Table1Category: TStringField;
  27.     Table1Common_Name: TStringField;
  28.     Table1SpeciesName: TStringField;
  29.     Table1Lengthcm: TFloatField;
  30.     Table1Length_In: TFloatField;
  31.     Table1Notes: TMemoField;
  32.     Table1Graphic: TGraphicField;
  33.     Table2PictureID: TIntegerField;
  34.     Table2PictureType: TStringField;
  35.     Table2Picture: TBlobField;
  36.     OpenPictureDialog1: TOpenPictureDialog;
  37.     ComboBox1: TComboBox;
  38.     fcLabel8: TfcLabel;
  39.     fcLabel9: TfcLabel;
  40.     CheckBox1: TCheckBox;
  41.     DBNavigator1: TDBNavigator;
  42.     Panel4: TPanel;
  43.     fcDBImager1: TfcDBImager;
  44.     DBImage1: TDBImage;
  45.     fcLabel3: TfcLabel;
  46.     Label1: TLabel;
  47.     Label2: TLabel;
  48.     fcLabel1: TfcLabel;
  49.     CheckBox2: TCheckBox;
  50.     procedure Table2BeforeOpen(DataSet: TDataSet);
  51.     procedure MultiImagerDblClick(Sender: TObject);
  52.     procedure MultiImagerCalcPictureType(ImageControl: TfcDBImager;
  53.       var PictureType: TfcImagerPictureType; var GraphicClassName: String);
  54.     procedure DBNavigator2Click(Sender: TObject; Button: TNavigateBtn);
  55.     procedure ComboBox1Change(Sender: TObject);
  56.     procedure FormShow(Sender: TObject);
  57.     procedure CheckBox1Click(Sender: TObject);
  58.     procedure DataSource2DataChange(Sender: TObject; Field: TField);
  59.     procedure CheckBox2Click(Sender: TObject);
  60.   private
  61.     { Private declarations }
  62.   public
  63.     { Public declarations }
  64.   end;
  65. var
  66.   DBImagerDemoForm: TDBImagerDemoForm;
  67. implementation
  68. {$R *.DFM}
  69. procedure TDBImagerDemoForm.Table2BeforeOpen(DataSet: TDataSet);
  70. begin
  71.   if GetClass('TJPEGImage') = nil then RegisterClass(TJpegImage);
  72. end;
  73. procedure TDBImagerDemoForm.MultiImagerDblClick(Sender: TObject);
  74.  var
  75.   blobstream:TBlobStream;
  76.   photostream:TFileStream;
  77.   extension:string;
  78. begin
  79.   with (Sender as TfcDBImager),DataSource do
  80.   try
  81.     if openpicturedialog1.execute then begin
  82.       DataSet.Edit;
  83.       photostream:=tfilestream.create(openpicturedialog1.filename,
  84.                                       fmopenread or fmsharedenywrite);
  85.       blobstream :=Tblobstream.create(DataSet.fieldbyname(DataField) as TBlobField,bmwrite);
  86.       try
  87.         with Openpicturedialog1 do
  88.         extension := AnsiUpperCase(ExtractFileExt(FileName));
  89.         If (extension='.JPG') or (extension='.JPEG') then
  90.            Dataset.FieldByName('PictureType').asstring := 'JPG'
  91.         else If (extension='.WMF') or (extension='.EMF') then
  92.            Dataset.FieldByName('PictureType').asstring := 'WMF'
  93.         else If (extension='.ICO') then
  94.            Dataset.FieldByName('PictureType').asstring := 'ICO'
  95.         else If (extension='.BMP') then
  96.            Dataset.FieldByName('PictureType').asstring := 'BMP';
  97.         blobstream.copyfrom(photostream,photostream.size);
  98.       except
  99.         photostream.free;
  100.         blobstream.free;
  101.         Dataset.Cancel;
  102.       end;
  103.     end;
  104.     if (DataSet.State in [dsInsert,dsEdit]) then DataSet.Post;
  105.   except
  106.     ShowMessage('Invalid Picture!');
  107.   end;
  108. end;
  109. procedure TDBImagerDemoForm.MultiImagerCalcPictureType(
  110.   ImageControl: TfcDBImager; var PictureType: TfcImagerPictureType;
  111.   var GraphicClassName: String);
  112. begin
  113.   with ImageControl.DataSource do
  114.     if DataSet.fieldbyname('PictureType').asstring = 'WMF' then
  115.       PictureType := fcptMetafile
  116.     else if DataSet.fieldbyname('PictureType').asstring = 'BMP' then
  117.       PictureType := fcptBitmap
  118.     else if DataSet.fieldbyname('PictureType').asstring = 'JPG' then
  119.       PictureType := fcptjpg
  120.     else if DataSet.fieldbyname('PictureType').asstring = 'ICO' then
  121.       PictureType := fcptIcon;
  122. end;
  123. procedure TDBImagerDemoForm.DBNavigator2Click(Sender: TObject;
  124.   Button: TNavigateBtn);
  125. begin
  126.   if Button = nbInsert then MultiImagerDblClick(MultiImager);
  127. end;
  128. procedure TDBImagerDemoForm.ComboBox1Change(Sender: TObject);
  129. begin
  130.   case ComboBox1.itemindex of
  131.   0:MultiImager.DrawStyle := dsCenter;
  132.   1:MultiImager.DrawStyle := dsNormal;
  133.   2:MultiImager.DrawStyle := dsProportionalCenter;
  134.   3:MultiImager.DrawStyle := dsStretch;
  135.   4:MultiImager.DrawStyle := dsTile;
  136.   end;
  137. end;
  138. procedure TDBImagerDemoForm.FormShow(Sender: TObject);
  139. begin
  140.   combobox1.itemindex := 2;
  141. end;
  142. procedure TDBImagerDemoForm.CheckBox1Click(Sender: TObject);
  143. begin
  144.   if Checkbox1.Checked then MultiImager.SmoothStretching := True
  145.   else MultiImager.SmoothStretching := False;
  146. end;
  147. procedure TDBImagerDemoForm.DataSource2DataChange(Sender: TObject;
  148.   Field: TField);
  149. begin
  150.   with (Sender as TDatasource).DataSet do
  151.     if FieldByName('PictureType').Text = 'JPG' then fcLabel9.Caption := 'JPG/JPEG'
  152.     else if FieldByName('PictureType').Text = 'BMP' then fcLabel9.Caption := 'BITMAP'
  153.     else if FieldByName('PictureType').Text = 'WMF' then fcLabel9.Caption := 'METAFILE'
  154.     else if FieldByName('PictureType').Text = 'ICO' then fcLabel9.Caption := 'ICON';
  155. end;
  156. procedure TDBImagerDemoForm.CheckBox2Click(Sender: TObject);
  157. begin
  158.   if Checkbox2.Checked then MultiImager.BitmapOptions.GrayScale := True
  159.   else MultiImager.BitmapOptions.GrayScale := False;
  160.   MultiImager.Invalidate;
  161. end;
  162. end.