Get simpler access JPEG files in Delphi to SQLServer database
Wang Dawei (WDCZZH)
After recently I saw two articles on "Delphi in the JPEG file to SQLServer", I feel that I have something to tell, but I have time, I have a simpler way of operation, and safe Reliable, I don't dare to enjoy alone, I am willing to release it with you. Tested in Delphi7.0 Win2000 SQLServer 2000, good operation, now thinking, source code is disclosed as follows:
Solutions:
1. The key is to dynamically convert the open JPEG file to the Tbitmap object and display it in the TIMAGE object;
2. Submit the displayed picture to the database.
In this example, a sample list is established in SQL Server 2000: Exam (XM Char (10), Photo Image);
Source code:
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.
The above is to access JPEG to the operation method in SQL Server. This article is just a throwing jade. I hope that all friends will come to see more, better, more practical application technology, and publish to 9CBS for everyone.
Welcome friends to come to Email communication: wdcwy@tom.com
QQ: 11711941