BCB 6 SP4 + SQL Server 2K Access JPEG image is absolutely easy to use!

xiaoxiao2021-03-06  21

In the BCB 6 SP4, the ad pasters, welcome prawn criticism to correct.

// OpenDialog1 Opens the JPEG image, edit1 saves the image address, image1 display image // other format image file has no test, you can try it.

OpenDialog1-> filename = ""; if (OpenDialog1-> execute ()) {edit1-> text = OpenDialog1-> filename; image1-> picture-> loadingfromfile (edit1-> text);}

// below: Save the image to the SQL Server database

IF (! Edit1-> text.isempty ()) {adoquery1-> close (); // Add adoConnent, configure adoquery1-> sql-> clear (); adoquery1-> sql-> add ("SELECT * FROM IMGS "); adoquery1-> open (); adoquery1-> insert ();

AdoQuery1-> FieldByname ("imgaddress") -> asstring = edit1-> text; adoquery1-> fieldByname ("imgid") -> asinteger = edit2-> text.Toint (); // Save Image number TBLOBFIELD * Field = Dynamic_cast (AdoQuery1-> FieldByname ("img")); // img is an image type of data field-> loadFromFile (edit1-> text); // This is the key, to call directly from the file. Don't adjust image1, so you can easily "JEPG ERROR # 41" error

AdoQuery1-> post (); adoquery1-> close ();

// Read the image from the database

AdoQuery1-> Close (); adoquery1-> sql-> clear (); adoQuery1-> sql-> add ("select * from imgs"); ANSISSIING DDD = "where imgid =" edit1-> text; adoquery1-> SQL-> Add (ddd); ADOQuery1-> Open (); if (ADOQuery1-> RecordCount == 1) {TStream * Stream1; TJPEGImage * Pjp = new TJPEGImage (); try {Stream1 = ADOQuery1-> CreateBlobStream (ADOQuery1- > FIELDBYNAME ("IMG"), BMREAD; PJP-> LoadFromstream (stream1); image2-> picture-> assign (pjp); delete stream1;} __finally {delete pjp;}}

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

New Post(0)