网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.金额大写转换.
.Delphi使用技巧四则.
.Delphi使用方法.
.给DBGrid添加鼠标滚动事件.
.零代码保存窗口运行状态.
.Delphi中的线程类--之(1).
.从当前的浏览器取得当前URL.
.Com接口入门细详(二).
.从DBGrid,StringGrid导出Excel.
.用程序模拟键盘和鼠标键盘.
.EXE工程和OCX工程的转化.
.如何在托盘图标实现漂亮的菜单.
.讲述如何开发一个控件,很有价值(.
.Delphi数据库编程教程(四).
.防止程序多次运行.
.Delphi数据库应用程序中常见错误.
.开发Web应用程序中Cookie使用的问.
.用Delphi编写DelTree程序.
.如何通过COM接口得到实现该接口的.
.Format的用法.

在DELPHI中更简单的存取JPEG文件到SQLSERVER数据库

发表日期:2006-2-4


 

最近在CSDN上看到两篇关于《DELPHI中存取JPEG文件到SQLSERVER》中的文章之后,觉得其中讲述的方法虽然有可取之处,但颇费时,我这里有更简单的操作方法,而且安全可靠,不敢一人独享,愿发布出来与大家共享。在Delphi7.0+Win2000+SqlServer 2000中测试通过,运行良好,现将思路、源码公开如下:

解决思路:

1、 关键在于将打开的JPEG文件动态转换为Tbitmap对象并显示在Timage对象中;

2、 将显示的图片提交到数据库中。

本例中在SQLSERVER2000中建立了一个试例表:exam(xm char(10),photo image);

 

程序源代码:

unit SavePic;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtDlgs, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ADODB, Buttons,

  StdCtrls,Jpeg;

 

type

  TForm1 = class(TForm)

    SpeedButton1: TSpeedButton;

    ADOConnection1: TADOConnection;

    Table1: TADOTable;

    DataSource1: TDataSource;

    DBGrid1: TDBGrid;

    DBImage1: TDBImage;

    Image1: TImage;

    SpeedButton2: TSpeedButton;

    OpenPictureDialog1: TOpenPictureDialog;

    Label1: TLabel;

    Label2: TLabel;

    Edit1: TEdit;

    SpeedButton3: TSpeedButton;

    procedure SpeedButton2Click(Sender: TObject);

    procedure SpeedButton1Click(Sender: TObject);

    procedure SpeedButton3Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

procedure TForm1.SpeedButton2Click(Sender: TObject);

var

  bmp1:TBitmap;

  jpg1:TJpegImage;

begin

 

  OpenPictureDialog1.DefaultExt:=GraphicExtension(TJpegimage);

  if OpenPictureDialog1.Execute then

     begin

     bmp1:=TBitmap.Create;

     jpg1:=TJpegImage.Create;

     try

     jpg1.LoadFromFile(OpenPictureDialog1.FileName);

     bmp1.Assign(jpg1);

     Image1.Picture.Bitmap.Assign(bmp1);

     finally

       jpg1.Free;

       bmp1.Free;

     end;

    end;

end;

 

procedure TForm1.SpeedButton1Click(Sender: TObject);

begin

  table1.Open;

  table1.insert;

  table1.fieldbyname('xm').asstring:=Edit1.Text;

  table1.FieldByName('photo').Assign(Image1.Picture);

  table1.post;

  table1.Refresh;

end;

end.

上一篇:Delphi开发单机瘦数据库程序要点 人气:4002
下一篇:delphi一句话帮助 人气:3982
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐