When the image control of WPF displays the byte array image pulled up by the database, an exception occurs. Generally, the image is not displayed when using () is used or the stream is closed.
Source. Metadata "raises an exception of the" system. notsupportedexception "type.
Byte [] B = file. readallbytes (directory. getcurrentdirectory () + " \ Test.jpg " ); // Using (memorystream MS = new memorystream (B )) // { // Bitmapimage Bm = new bitmapimage (); // BM. begininit (); // // Long A = Ms. Seek (0, seekorigin. Begin ); // BM. streamsource = MS; // BM. endinit (); // Image_1.source = bm; // }
// The following code is normal, because using () is removed ()
Memorystream MS = New Memorystream (B); bitmapimage BM = New Bitmapimage (); BM. begininit (); // Long A = Ms. Seek (0, seekorigin. Begin ); BM. streamsource = MS; BM. endinit (); image_1.source = Bm;
How to handle exceptions when the image control of WPF displays stream images provided by memorystream