c# - Destroying stream cause destroying the bitmap -
i have like:
       public bitmap getbitmap()        {                      byte[] bytearray= bring somewhere                 using (stream stream = new memorystream(bytearray))             {                 return new bitmap(stream);             }         }   when use method outside bitmap crushed. if stepped "using" scope bitmap exists , works fine. seems disposing stream cause disposing bitmap.. question is: need deep copy? how should perform it?
when dispose bitmap lost, indeed need perform deep copy. code should be:
public static bitmap getbitmap() {     byte[] bytearray = bring somewhere     using (stream stream = new memorystream(bytearray))     {         var tempbitmap = new bitmap(stream);         return new bitmap(tempbitmap); // deep-copy bitmap     } }   by way, primitive types, byte written in small case.
Comments
Post a Comment