在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