打印本文 打印本文 关闭窗口 关闭窗口
BCB存取图片等信息!
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1739  更新时间:2009/4/23 18:37:24  文章录入:mintao  责任编辑:mintao
nbsp;  dm_police->y_stress_man_photo->Append();
                dm_police->y_stress_man_photo->FieldByName("c_card")->Value=Edit3->Text;
                TBlobField * pField=(TBlobField *)dm_police->y_stress_man_photo->FieldByName("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);
在http://expert.csdn.net/Expert/topic/1383/1383453.xml?temp=.9190485中有:
  Table1->Close();
        Table1->Open();
        Table1->Append();
        Table1->FieldByName("ID")->AsString=Edit1->Text.ToInt();
        Edit1->Text = StrToInt(Edit1->Text.ToInt()+1);
        Table1->FieldByName("Name")->AsString=OpenDialog1->FileName;
        Image1->Picture->LoadFromFile(OpenDialog1->FileName) ;

        TBlobField * pField=(TBlobField *)Table1->FieldByName("Entity");
        TStream *Stream2;
        TMemoryStream *tt=new TMemoryStream();
        Graphics::TBitmap * pBitmap=new Graphics::TBitmap();
        pBitmap->Assign(Image1->Picture->Graphic);
        pBitmap->SaveToStream(tt);

        pField->LoadFromStream(tt);
        Table1->Post();
说了这么多,你可能发现了,上边的代码都有一个共性,那就是用流来操作,好好,不知道你有没有发现呢!
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 determine 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 that 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 introduced in TGraphic, so it 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:
TStream is the base class type for stream objects that can read from or write to various kinds of storage media, such as disk files, dynamic memory, and so on.
Use specialized stream objects to read from, write to, or copy information stored in a particular medium. Each descendant of TStream implements methods for transferring information to and from a particular storage medium, such as a disk file, dynamic memory, and so on.  In addition to methods for reading, writing, and copying bytes to and from the stream, stream objects permit applications to seek to an arbitrary position in the stream. Properties of TStream provide information about the stream, such as its size and the current position in the stream.
TStream also introduces methods that work in conjunction with components and filers for loading and saving components in simple and inherited forms. These methods are called automatically by global routines that initiate component streaming. They can also be called directly to initiate the streaming process. Note, however, that component streaming always involves two additional objects:
A component object that is passed as a parameter to the stream’s methods.
A filer object that is automatically created by the stream, and associated with the stream.
TStream should not be instantiated; it relies on pure virtual methods that must be overridden in descendant classes. Descendant stream objects, such as memory and file streams used for component streaming, are created automatically by the global functions ReadComponentRes and WriteComponentRes. For streaming other kinds of information, choose a descendant class according to the specific data and storage needs.

 

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口