How to store image information to the database! Too many times we have to save pictures, movies, mp3, how to deal with this information! Too many cases, we believe that the path information should be stored, but when we consider the problem to be backed up, and when the database is to be transferred, it may cause us more inconvenience! I think it is a good idea to store image information in some cases; just if we are designing a database, if the amount of data is small, it is possible to reduce the number of views in the view; design the database It is a very flexible process, not that the book can complete the task, take into account the use of programmers and users to take a fortune. Frequently visiting the 9CBS, often encounter too many identical questions, I think it should be summed up, there is a little help for the later people, thank you for their help for my predecessors; what is discussed in BCB Access image information. The first is implemented with TadoQuery, which is implemented with the SQL statement.
Reference http://expert.9cbs.net/expert/topic/1805/1805073.xml?temp =.556637 This is written, if you don't want to find it, the original code is as follows: if (OpenPictureDialog1-> Execute ()) { String strsql = "INSERT INTO TABLE1 (Content); strsql = strsql " VALUES (: Picture) "; try {adoquery1-> close (); adoquery1-> sql-> clear (); adoquery1-> sql-> add (strsql); adoquery1-> parameters-> parambyname ("Picture") -> LoadFromFile (OpenPictureDialog1-> filename, ftblob); adoquery1-> execSql ();} catch (...) {return;}} also has one It is written in Delphi, the original code is as follows: // (1) If you are using a TTable, you should first place its readOrthly property as false, then call the Edit function; // (2) If you are using TQuery, you want to first place its requestLive property as true, then call the Edit function; var MS: tadobstream; begin query1.edit; // can only be Edit; can not be append and insert; ms: = tadobstream.create (TBLOBFIELD Query1.fieldbyName ('bmp')), bmread); ms.seek (0, Sofrombeginning); ms.savetofile ('d: /l.bmp'); query1.post; ms.free; end; same big brother The BCB code is as follows: // (1) If you are using a TTable, you will first place its readOrthly property as false, and then call Edit function; // (2) If you are using tQuery, you should first place its RequestLive property as true, then call the Edit function; void __fastcall tform1 :: bitbtn1click (Tobject * sender) {Table1-> Edit () ;; // can only be edit (); can not be append () and INSERT (); tblobfield * pfield = (tblobfield *) Table1-> FieldbyName ("Figure word"); TBLOBSTREAM * PMEM = New TBLOBSTREAM (Pfield, BMWRITE) ; PMEM-> Seek (0, SOFROMBEGINNING); graphics :: tbitmap * Pbitmap = new graphics :: tbitmap (); pbitmap-> loadingfromfile ("d: //image/a.bmp"); pbitmap-> savetostream PMEM); table1-> post (); delete Pbitmap; delete PMEM;
} Similarly similar BCB code is as follows (there is no debugging on the upper side, but the truth written is still the same, it is a field and a stream object in the database, then operates on the stream): TmemoryStream * stream = new TMEMORYSTREAM ); Image1-> Picture-> Bitmap-> savetostream (stream); adotable1-> INSERT (); adotable1-> fieldbyName ("title") -> asstring = Edit1-> text; ((Tgraphicfield *) (adotable1-> FIELDBYNAME ("Content"))) -> LoadFromstream (stream); adotable1-> post (); delete stream; Reading method is similar, when you make everyone, or write it, as follows: include
(! F_Photo-> DataSet-> Active) template
Hold a variety of formats: f (openpicturedialog1-> execute ()) {dataset-> edit (); tblobfield * Field = (tblobfield *) DataSet-> FieldByname ("photo"); Field-> LoadFromFile (OpenPictureDialog1-> FileName) DataSet-> FieldByname ("photoformat") -> asstring = extractfileext (OpenPictureDialog1-> filename) .uppercase (); ataset-> post (); at http://expert.9cbs.net/expert/topic/1348/ 1348495.xml? Temp = .5143854, JSP boss method is actually the same! : If return; ADOTable1-> Insert (); ADOTable1-> FieldByName ( "title") -> AsString = Edit1-> Text; TADOBlobStream * Stream = (TADOBlobStream *) ADOTable1-> CreateBlobStream (OpenPictureDialog1-> Execute ()!) (ADOTABLE1-> FieldbyName ("Content"), BMWRITE); stream-> loadingfromfile (OpenPictureDialog1-> filename); delete stream; adotable1-> post (); at http://expert.9cbs.net/expert/topic/ ? 1326 / 1326759.xml temp = .3533899, the brother of wage earners method: read TBlobField * pField = (TBlobField *) dm_police-> y_find-> FieldByName ( "image_photo"); TClientBlobStream * pmem = new TClientBlobStream (pField, bmRead ); pmem-> Seek (0, soFromBeginning); // Graphics :: TBitmap * pBitmap = new Graphics :: TBitmap (); TJPEGImage * pBitmap = new TJPEGImage (); pBitmap-> LoadFromStream (pmem); Image2-> Picture -> Assign (pBitmap); delete pmem; delete pBitmap; write dm_police-> y_stress_man_photo-> Open (); dm_police-> y_stress_man_photo-> Append (); dm_police-> y_stress_man_photo-> FieldByName ( "c_card") -> Value = Edit3-> TEX T; TBLOBFIELD * PFIELD = (TBLOBFIELD *) DM_POLICE-> y_stress_man_photo-> infensename ("
image_photo "); TClientBlobStream * pmem = new TClientBlobStream (pField, bmWrite); pmem-> Seek (0, soFromBeginning); // Graphics :: TBitmap * pBitmap = new Graphics :: TBitmap (); TJPEGImage * pBitmap = new TJPEGImage ( ); pBitmap-> Assign (Image2-> Picture-> Graphic); pBitmap-> SaveToStream (pmem); delete pmem; delete pBitmap; dm_police-> y_stress_man_photo-> Post (); dm_police-> y_stress_man_photo-> ApplyUpdates (-1 ); In http://expert.9cbs.net/expert/topic/1383/1383453.xml?temp=.9190485: Table1-> Close (); table1-> open (); table1-> append () Table1-> FieldByname ("ID") -> asstring = Edit1-> text.Toint (); edit1-> text = start (edit1-> text.toint () 1); table1-> infensename ("name" ) -> asstring = Opendialog1-> filename; image1-> Picture-> LoadFromFile (OpenDialog1-> filename); tblobfield * pfield = (tblobfield *) Table1-> FieldByName ("Entity"); t Stream * Stream2; TMemoryStream * tt = new TMemoryStream (); Graphics :: TBitmap * pBitmap = new Graphics :: TBitmap (); pBitmap-> Assign (Image1-> Picture-> Graphic); pBitmap-> SaveToStream (tt);
Pfield-> LoadFromStream (TT); Table1-> post (); say so much, you may find that there is a commonality in the code, that is, use the flow to operate, don't know if you have discovered!
TADOBlobStream:. Use c to access or modify the value of a BLOB or memo field in an ADO dataset BLOB fields are represented by TBlobField objects and descendants of TBlobField such as TGraphicField and TMemoField.TADOBlobStream allows objects that have no specialized knowledge of how data is stored in a BLOB field (raw binary data) to read or write such data by employing the uniform stream interface.To use an ADO BLOB stream, create an instance of TADOBlobStream, use the methods of the stream to read or write the data, and then free the BLOB stream. Do not use the same instance of TADOBlobStream to access data from more than one record. Instead, create a new TADOBlobStream object every time you need to read or write BLOB data on a new record.Use the Read method to copy the data from BLOB field object to a null-terminated string (or comparable) buffer. use the Write method to copy from buffer to BLOB field object. When reading data from the BLOB field object, use the Size property to dete rmine the volume of the field's contents and to allocate the correct amount of space in memory for the receiving buffer.TMemoryStream:. Use TMemoryStream to store data in a dynamic memory buffer that is enhanced with file-like access capabilities TMemoryStream provides the general I / O capabilities of a stream object while introducing methods and properties to manage a dynamic memory buffer.Memory streams are useful as intermediary objects that can hold information as well as read it from or write it to another storage medium. They provide a useful format for comparing THE Contents of Streams, or for manipulating data this is stored in a less accessible medium. TJPEGIMAGE:
Use TJPEGImage to read and write jpeg compressed image data. TJPEGImage handles the digital compression and decompression of still images for use in computer systems. It uses the data from an instance of TJPEGData, which contains the actual jpeg data source and is never modified. Each jpeg image object may share its TJPEGData object with other instances of a jpeg image by creating copies using the Assign method. The jpeg data source handles reference counting for the jpeg image objects that are linked to it.TJPEGImage has an internal bitmap that represents the jpeg image. This internal image and the original source of the jpeg image are read only. TJPEGImage has properties that determine how each instance will handle color conversion, compression, decompression, performance, and so on.The following are characteristics of this object. A TJPEGImage Object: HAS No Canvas (SO IT Cannot Draw Onto a Canvas). However, Tjpegimage Implements The Protected Draw Method Introducesd in Tgraphic, SO i t can draw itself on the canvas of another object. Provides no access to the internal bitmap image that it creates for the JPEG image. Performs reference counting and handle sharing by means of the TJPEGData object. Multiple instances can refer to the same TJPEGData image. Tjpegdata is the actual Owner of the file handle to the jpeg data source.tblobfield:
TBlobField encapsulates the fundamental behavior common to binary large object (BLOB) fields. BLOB fields are database fields that contain raw binary data of arbitrary length. BLOB fields can represent different arbitrarily large data types. These data types are distinguished in the header of the binary data.In addition to the field types supported directly, TBlobField is the direct ancestor of two BLOB field components:. TMemoField (ftMemo) and TGraphicField (ftGraphic) These descendants represent BLOB fields that have headers peculiar to memos or graphic data, respectively.TBlobField introduces new methods to support streaming data to and from the BLOB field and to support copying raw binary data between the BLOB field and a binary file. You can also use the stream returned by a dataset's CreateBlobStream method to read or write the data managed by a Blob Field.if you Use the Fields Editor At Design Time To Create a Persistent Field Component for the blob Field, you can access it by Name at runtime. When Using Dynamic Field Components, You CAN Access The Tblobfield Instance Using The Dataset's Fields Property Or FieldByname Method. TSTREAM: