在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
StdCtrls
Jpeg;
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 SpeedButton
Click(Sender: TObject);
procedure SpeedButton
Click(Sender: TObject);
procedure SpeedButton
Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form
: TForm
;
implementation
{$R *
dfm}
procedure TForm
SpeedButton
Click(Sender: TObject);
var
bmp
:TBitmap;
jpg
:TJpegImage;
begin
OpenPictureDialog
DefaultExt:=GraphicExtension(TJpegimage);
if OpenPictureDialog
Execute then
begin
bmp
:=TBitmap
Create;
jpg
:=TJpegImage
Create;
try
jpg
LoadFromFile(OpenPictureDialog
FileName);
bmp
Assign(jpg
);
Image
Picture
Bitmap
Assign(bmp
);
finally
jpg
Free;
bmp
Free;
end;
end;
end;
procedure TForm
SpeedButton
Click(Sender: TObject);
begin
table
Open;
table
insert;
table
fieldbyname(
xm
)
asstring:=Edit
Text;
table
FieldByName(
photo
)
Assign(Image
Picture);
table
post;
table
Refresh;
end;
end
From:http://tw.wingwit.com/Article/program/Delphi/201311/8391.html