The previous time in the project, when the byte array is converted to an image, a general error occurs occasionally in "GDI +". This is the case when the image is converted to a byte array. The solution is as follows:Code(Error code:
1. Public static byte [] imagetobytearray (image imagein) 2. {3. Using (memorystream MS = new memorystream () 4. {5. If (imagein! = NULL) 6. {7. imagein. Save (MS, imageformat. JPEG); 8.} 9. Return Ms. toarray (); 10.} 11 .}
Method 1:
1. Public static byte [] imagetobytearray (image imagein) 2. {3. Using (memorystream MS = new memorystream () 4. {5. If (imagein! = NULL) 6. {7. bitmap T = new Bitmap (imagein); 8. t. save (MS, system. drawing. imaging. imageformat. JPEG); 9 .} 10. return Ms. toarray (); 11 .} 12 .}
Method 2:
1. Public static byte [] imagetobytearray (image imagein) 2. {3. Using (memorystream MS = new memorystream () 4. {5. If (imagein! = NULL) 6. {7. bitmap PIC = new Bitmap (imagein. width, imagein. height); 8. graphics G = graphics. fromimage (PIC); 9. g. drawimage (imagein, 0, 0, imagein. width, imagein. height); 10. g. dispose (); 11. PIC. save (MS, imageformat. JPEG); 12. PIC. dispose (); 13 .} 14. return Ms. toarray (); 15 .} 16 .}