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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -