时间: 2021-07-31 作者:daque
迩来在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.