熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

在Delphi中簡單的存取JPEG文件到SQLServer

2022-06-13   來源: Delphi編程 
在Delphi+Win+SqlServer 中測試通過運行良好現將思路源碼公開如下
  
  解決思路
   關鍵在於將打開的JPEG文件動態轉換為Tbitmap對象並顯示在Timage對象中
  
   將顯示的圖片提交到數據庫中
  
  本例中在SQLSERVER中建立了一個試例表exam(xm char()photo image)
  
  程序源代碼
  
  unit SavePic;
  
  interface
  
  uses
  
   Windows Messages SysUtils Variants Classes Graphics Controls Forms
  
   Dialogs ExtDlgs ExtCtrls DBCtrls Grids DBGrids DB ADODB Buttons
  
   StdCtrlsJpeg;
  
  type
  
   TForm = class(TForm)
  
    SpeedButton: TSpeedButton;
  
    ADOConnection: TADOConnection;
  
    Table: TADOTable;
  
    DataSource: TDataSource;
  
    DBGrid: TDBGrid;
  
    DBImage: TDBImage;
  
    Image: TImage;
  
    SpeedButton: TSpeedButton;
  
    OpenPictureDialog: TOpenPictureDialog;
  
    Label: TLabel;
  
    Label: TLabel;
  
    Edit: TEdit;
  
    SpeedButton: TSpeedButton;
  
    procedure SpeedButtonClick(Sender: TObject);
  
    procedure SpeedButtonClick(Sender: TObject);
  
    procedure SpeedButtonClick(Sender: TObject);
  
   private
  
    { Private declarations }
  
   public
  
    { Public declarations }
  
   end;
  
  var
  
   Form: TForm;
  
  implementation
  
  {$R *dfm}
  
  procedure TFormSpeedButtonClick(Sender: TObject);
  
  var
  
   bmp:TBitmap;
  
   jpg:TJpegImage;
  
  begin
  
   OpenPictureDialogDefaultExt:=GraphicExtension(TJpegimage);
  
   if OpenPictureDialogExecute then
  
     begin
  
     bmp:=TBitmapCreate;
  
     jpg:=TJpegImageCreate;
  
     try
  
     jpgLoadFromFile(OpenPictureDialogFileName);
  
     bmpAssign(jpg);
  
     ImagePictureBitmapAssign(bmp);
  
     finally
  
      jpgFree;
  
      bmpFree;
  
     end;
  
    end;
  
  end;
  
  procedure TFormSpeedButtonClick(Sender: TObject);
  
  begin
  
   tableOpen;
  
   tableinsert;
  
   tablefieldbyname(xm)asstring:=EditText;
  
   tableFieldByName(photo)Assign(ImagePicture);
  
   tablepost;
  
   tableRefresh;
  
  end;
  
  end
From:http://tw.wingwit.com/Article/program/Delphi/201311/8391.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.