Nobody can answer this question!

| Following sample C# codes are from MSDN, to create a bmp file from an BLOB column in Microsoft Access DB, which was also imported from another bmp file. =============================================================
DB_Conn_String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Inetpub\\wwwroot\\ruiwen.mdb"; ImgConn = new OleDbConnection( DB_Conn_String ); ImgDataAdapter =new OleDbDataAdapter();
FileStream fs; // Writes the BLOB to a file (*.bmp).BinaryWriter bw; // Streams the BLOB to the FileStream object.int bufferSize = 100;// Size of the BLOB buffer.byte[] outbyte =newbyte[bufferSize];// The BLOB byte[] buffer to be filled by GetBytes.long retval;// The bytes returned from GetBytes.long startIndex = 0;// The starting position in the BLOB output.int img_id = 0;// The image #.// Open the connection and read data into the DataReader.OleDbCommand cmd; DataRow my_row; // Create the SelectCommand.cmd = new OleDbCommand( "SELECT * FROM rw_obj", ImgConn );ImgConn.Open(); OleDbDataReader myReader = cmd.ExecuteReader( CommandBehavior.SequentialAccess ); while( myReader.Read() ){ img_id++; // Create a file to hold the output.fs = new FileStream( "c:\\rw" + img_id + ".bmp", FileMode.OpenOrCreate, FileAccess.Write );bw = new BinaryWriter( fs );// Reset the starting byte for the new BLOB.startIndex = 0; // Read the bytes into outbyte[] and retain the number of bytes returned.retval = myReader.GetBytes( 2, startIndex, outbyte, 0, bufferSize ); // Continue reading and writing while there are bytes beyond the size of the buffer.while (retval == bufferSize){ bw.Write(outbyte); bw.Flush(); // Reposition the start index to the end of the last buffer and fill the buffer.startIndex += bufferSize; retval = myReader.GetBytes( 2, startIndex, outbyte, 0, bufferSize ); } // Write the remaining buffer.bw.Write( outbyte, 0, ( int )retval - 1 );bw.Flush(); // Close the output file.bw.Close(); fs.Close(); } // Close the reader and the connection.myReader.Close(); ImgConn.Close(); ==============================================================However, the program is very unsuccessful. Although the new bmp file was generated, but it is inaccessible to Paint Brush and other image tools, and even the size was different from the original bmp file. If there is any solution, whether it is also applicable to jpg and other image formats? 
|
|
| | Report |