1. A general error occurs in GDI +. (Read images from the database and write them back to the database without modification)
Reference: http://www.cnblogs.com/wudingfeng/archive/2008/07/24/1250564.html
Byte [] PIC = Null ; // Saved Image
If (Picturebox1.image ! = Null )
{
// Solve a general error in "GDI +. "Key
// Bytes -----------------------------------------------------------------------------------
Image img = Picturebox1.image; // Reading picturebox Images
// If the file format is null, it is set to BMP.
System. Drawing. imaging. imageformat rawformat = Null ;
Rawformat = (IMG. rawformat = Null ) ? System. Drawing. imaging. imageformat. BMP: IMG. rawformat;
Bitmap BMP 1 = New Bitmap (IMG ); // Create a bitmap type BMP variable to read the file.
Bitmap BMP 2 = New Bitmap (IMG. Width, IMG. Height ); // Create the BMP 2 variable of the second bitmap type
Graphics draw = Graphics. fromimage (image) BMP 2 );
Draw. drawimage (image) BMP 1, 0 , 0 );
Picturebox1.image = (Image) BMP 2;
Draw. Dispose ();
BMP 1.dispose ();
// BMP 2.dispose (); // Cannot be released
// Bytes -----------------------------------------------------------------------------------
System. Io. memorystream imgms = New System. Io. memorystream ();
Picturebox1.image. Save (imgms, rawformat );
Byte [] Imgbyte = Imgms. toarray ();
If (Imgms. Length > 64 * 1024 )
{
Picturebox1.image = Null ; // Clear Image
If (Imgms ! = Null ) {Imgms. Dispose ();} // Release resources
System. Windows. Forms. MessageBox. Show ( " Select an image with a capacity less than or equal to 64 KB! " , " Warning " ,
System. Windows. Forms. messageboxbuttons. OK, system. Windows. Forms. messageboxicon. Warning );
}
Imgms. Read (imgbyte, 0 , Convert. toint32 (imgms. Length ));
PIC = Imgbyte;
Imgms. Close ();
If (Imgms ! = Null ) {Imgms. Dispose ();} // Release resources
}
/***************/
Mysqlda. updatecommand. Parameters. addwithvalue ("@ Photo",PIC );
2. You cannot create a graphics object from an image with indexed pixel format.
Reference: http://hi.baidu.com/1987raymond/blog/item/0d2e86a151d969834710649b.html
(Watermark example reference: http://dong.hongjun888.blog.163.com/blog/static/2081208420098172655812)
Follow the preceding stepsCodeA general error occurs in [1.gdi+. (Read images from the database and write them back to the database without modification)]
As longNewBitmap (IMG. Width, IMG. Height, pixel format); To remove the pixel format (I only encounter this situation for the time being, and find a similar solution)
Bitmap BMP 2 = New Bitmap (IMG. Width, IMG. Height ); // Create the BMP 2 variable of the second bitmap type