问题描述
我应该分配内存或存储流的只是对象:
这是OK?
Should I allocate the memory or just the object of the memory stream:Is this OK?
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
如果我需要定义MemoryStream的大小,如何从位图得到它?
If I need to define the MemoryStream size, how can I get it from Bitmap?
推荐答案
.NET是一个管理环境:具体而言,内存分配代表您的.NET运行时通常是管理。你通常不需要自己分配内存。
.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.
不过,有时你需要使用通知运行时,当你有记忆完成关闭()
或的Dispose()
。在使用
语句可用于包装资源,如的MemoryStream
来告诉大家,内存可以被回收的运行时间。
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.
这篇关于保存位图到MemoryStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!