[C # (winform)]-intractable diseases

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.