Saving a bitmap into a MemoryStream

后端 未结 2 641
感情败类
感情败类 2021-02-12 01:43

Should I allocate the memory or just the object of the memory stream: Is this OK?

MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, Syste         


        
2条回答
  •  长发绾君心
    2021-02-12 02:14

    .NET is a managed environment: specifically, memory allocation is usually managed on your behalf by the .NET runtime. You don't typically need to allocate the memory yourself.

    Sometimes, however, you do need to inform the runtime when you've finished with memory by using Close() or Dispose(). The using statement can be used to wrap a resource such as MemoryStream to tell the runtime that the memory can be reclaimed.

提交回复
热议问题