Second, how to handle multimedia data 1. Multimedia data storage
Multimedia information includes images, sounds, and videos, they are existing in the form of binary data set, and the object processed in this system is an image. SQL Server provides an Image data type to store variable length binary data (size range is 0 ~ 2GB). However, the image field does not load multimedia data directly, and some intermediate steps must be stored in. The following is a storage of image data as an example, and give you how to implement these intermediate steps in Delphi.
The TSTREAM data type in Delphi stores characters or non-character data in the form of streams, just like a small-sized temporary cache area in memory. It not only makes it easy to read and write external files, but also directly transfer all the data in the stream to the database, so it is very suitable to use it as a bridge to complete data storage.
The following SaveToImage function is functional in the Image field of the TSTREAM data to the data table.
function SavetoImage (const Stream: TStream; const AField: TField): boolean; varFieldStr: string; PFieldStr: PChar; beginResult: = false; if (Assigned (AField)) and (Assigned (Stream)) thenbegintryStream.Seek (0,0 ); Setlength; pfieldstr: = pchar (fieldstr); stream.read (pfieldstr ^, stream.size); Afield.Value: = fieldStr; result: = true; eXcend;
Below is a segment of the SaveToImage function to complete the image data store.
VARFS: TFileStream; Beginfs: = TFileStream.create ('c: /car001.jpg' ,fmopenread); SavetoImage (fs, adodataset1.fieldbyName); fs.free;
Among them, AdoDataSet1 is an ADO data set control that is connected to a database, and ST_IMG is an Image field.
2. Multimedia data transfer
With the BCP utility taken by SQL Server, you can easily copy the database sections or all data, including binary data. The copied multimedia data can be transferred to the remote monitoring computer over a network or mobile storage device, and then use BCP to copy them to the monitoring database to play back or other processing for multimedia data. Below is a program fragment that simplifies copies data from the database to external files and copying the database from the external file.
Vars1: String; Begins1: = 'BCP "SELECT * AROM ST2002..st2002_sf where st_flag = 1" queryout c: /media_data.dat -n -p -s sunnynt / hy2002'; Winexec (Pchar (S1), SW_SHOW); END;
Where "SELECT * FROM ST2002..st2002_sf where st_flag = 1" indicates that data from the ST2002 database of ST2002 database, "c: /media_data.dat" is output data file, the parameter Queryout represents copying data from the query to external files, -N represents a large-capacity data replication operation, and -p represents a database server or instance of data replication using the default password, the -s subscription.
Vars1: String; Begins1: = 'BCP ST2002..st2002_sf in c: /media_data.dat -n -e -p -s sunnynt / hy2002'; WINEXEC (PCHAR (S1), SW_SHOW); END; where parameter IN is Data is copied from external files to the data table.
3. Multimedia data playback
Similar to the same memory, multimedia data is played back to the bridge with the TSTREAM data type, and it is basically stored inverse processes.
The functionality of the LoadFromImage function is to load the image field of the data table into TSTREAM.
function LoadfromImage (const AField: TField; const Stream: TStream): boolean; varResultStr: string; PResultStr: PChar; beginResult: = false; if (Assigned (AField)) and (Assigned (Stream)) thenbegintryResultStr: = AField.Value; PRESULTSTR: = PCHAR (RESULTST); Stream.write (PRESULTSTR ^, Length (Resultstr)); stream.seek (0); result: = true; eXcend; end;
Below is a program fragment that calls the LoadFromImage function to transfer image data in the data table image field to an external file and use the image display control to play back the image.
varFS: TFileStream; beginFS: = TFileStream.Create ( 'c: /Car001.jpg',fmCreate); LoadfromImage (adodataset1.fieldbyname (' st_img '), FS); FS.Free; image1.picture.LoadFromFile (' c: / Coar001.jpg');
Third, small knot
Other multimedia data types, such as sound, video, etc. The transfer process is exactly the same as the image of the image, but the playback portion should use different media play controls for different media types.
The prototype program described above is debugged in the Delphi 5/6/7 SQL Server 2000 Standard Edition. After appropriate expansion and modification, these procedures have been verified in the highway toll system developed by the author. Similarly, these programs can also be used in applications such as student status management, archival management, personnel management, commodity transactions, etc. involving multimedia data.
Nowadays, digital devices such as DC, DV, MP3 are gradually in-depth in our lives and work, and multimedia information such as images, videos, sounds are exploded, how to effectively manage these multimedia information becomes us. In front of the topic. This paper briefly discusses several basic issues that use the SQL Server database to manage multimedia information. The principle is equally suitable for the front-end development tools such as Sybase, Oracle and other databases and PowerBuilder, VB.