Delphi Access JPEG file to SQL Server database (continuous)

xiaoxiao2021-03-06  39

After the "Delphi Access JPEG file to SQL Server Database", there are many netizens to represent support and related technical consultations. First, I would like to express my heartfelt thanks to those who care about this article.

Since users need to make a file management system, access JPEG files into the SQL 2000 database, but in dbimage and qrdbimage, JPEG files cannot be displayed normally, this is the limit of Borland, although the use of third-party controls can meet the requirements. But we still come to the original implementation of this technology, in fact, the principle is very simple, since we can store the JPEG file in "Delphi Access JPEG file to SQL Server database", you can also display it in Image, but contact DB class The image display control will not pass, we can convert to the BMP file before the JPEG file is stored in the database and then store it into the database, the program running the environment Delphi5 ADO SQL 2000 desktop version Win98SE2 final version, the database is stored in the database The type is image, the program source code is as follows:

Unit unit1;

Interface

Uses

Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,

DB, DBCTRLS, GRIDS, DBGRIDS, ADODB, EXTDLGS, JPEG, ExtCtrls, stdctrls

Type

TFORM1 = Class (TFORM)

Adoconnection1: Tadoconnection;

Adoquery1: TadoQuery;

DataSource1: TDataSource;

DBGRID1: TDBGRID;

Dbimage1: TDBIMAGE;

AdoQuery1ID: TStringfield;

AdoQuery1field: tstringfield;

AdoQuery1Style: Tstringfield;

AdoQuery1System: tstringfield;

AdoQuery1Date: TDATETIMEFIELD;

AdoQuery1Person1: Tstringfield;

AdoQuery1Person2: Tstringfield;

AdoQuery1Person3: Tstringfield;

AdoQuery1Photo: TBLOBFIELD;

AdoQuery1Description: TStringfield;

OpenPictureDialog1: TopenPictureDialog;

Image1: timage;

Button1: tbutton;

Memo1: TMEMO;

Procedure Dbimage1Click (Sender: TOBJECT);

Procedure Button1Click (Sender: TOBJECT);

Procedure FormShow (Sender: TOBJECT);

Private

{Private Declarations}

public

{Public declarations}

END;

VAR

FORM1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TFORM1.DBIMAGE1CLICK (Sender: TOBJECT);

VAR

PicStream: tadoblobstream;

BMPPIC: TBITMAP;

JPGPIC: TJPEGIMAGE;

Bmpstream: TMemoryStream;

Begin

if Form1.openPicturedialog1.execute THEN

Begin

if extractfileext (form1.openpicturedialog1.filename) = '. BMP' THENBEGIN

Adoquery1.edit;

PicStream: = TadoblobStream.create (TBLOBFIELD (AdoQuery1Photo), BMWRITE

// Note: AdoQuery1Photo in the present sentence is Name of fixed field photo of ADOQUERY1.

/ / The user needs to manually add a fixed field, or you can use Fields [i] to choose, this is

// "Delphi Access JPEG File to SQL Server Database" This article has no comments in this article, so that many friends do not

// Compile success.

PicStream.LoadFromFile (OpenPictureDialog1.FileName);

PICSTream.position: = 0;

Adoquery1.edit;

Tblobfield (AdoQuery1Photo) .loadFromstream (PICSTREAM);

Adoquery1.post;

Adoquery1.edit;

PICSTream.free;

end

Else

Begin

JPGPIC: = TjpegImage.create;

BMPPIC: = Tbitmap.create;

Bmpstream: = TMEMORYSTREAM.CREATE;

JPGPIC.LoadFromFile (OpenPictureDialog1.FileName);

BMPPIC.Assign (JPGPIC);

BMPPIC.SAVETOSTREAM (BMPStream);

Adoquery1.edit;

PicStream: = TadoblobStream.create (TBLOBFIELD (AdoQuery1Photo), BMWRITE

// Note: AdoQuery1Photo in the present sentence is Name of fixed field photo of ADOQUERY1.

/ / The user needs to manually add a fixed field, or you can use Fields [i] to choose, this is

// "Delphi Access JPEG File to SQL Server Database" This article has no comments in this article, so that many friends do not

// Compile success.

PICSTream.LoadFromstream (bmpstream);

PICSTream.position: = 0;

Adoquery1.edit;

Tblobfield (AdoQuery1Photo) .loadFromstream (PICSTREAM);

Adoquery1.post;

JPGPIC.FREE;

BMPPIC.FREE;

Bmpstream.free;

Adoquery1.edit;

PICSTream.free;

END;

END;

END;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

Memo1.Lines.Add (Form1.OpenPictureDialog1.Filter);

END;

Procedure TFORM1.FORMSHOW (Sender: TOBJECT);

Begin

Form1.openpicturedialog1.filter: = 'all * .jpg; *. jpeg; *. bmp; | * .jpg; *. jpeg; *. bmp;)';

END;

End.

The function code to this is as follows, I hope to help friends who need information in this area.

转载请注明原文地址:https://www.9cbs.com/read-78593.html

New Post(0)