本文介绍了何时可以关闭用于在C#中的PictureBox控件中支持GIF动画的MemoryStream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我在互联网上找不到关于这种情况的任何信息,所以我希望有人可以启发我。



我有一个带有图片框控件的应用程序,用于显示动画GIF图像。我使用OpenFileDialog将图像加载到图片框中,然后使用MemoryStream将图像转换为Base64字符串并将该字符串存储到列表中。从列表中加载图像时,图像将使用MemoryStream从Base64字符串转换回图像并加载到图片框中。



问题:为了动画要在图片框中设置动画的GIF,我必须让MemoryStream保持打开状态。否则动画GIF将不会动画。但每次我将新图像加载到图片框中时,我都会创建一个新的MemoryStream实例。通过这种方式加载图像而不关闭其关联的MemoryStreams,我假设我的应用程序将从图片框中不再显示的所有图像中留下一堆剩余的MemoryStream。我希望通过关闭不再需要的任何MemoryStream来保持我的应用程序的内存使用率低,但我不能在创建它的函数内关闭MemoryStream而不影响当前图像的动画。

解决方案


I can't find any information on the Internet about this scenario, so I'm hoping someone can enlighten me.

I have an app with a picturebox control that is used to display animated GIF images. I load an image into the picturebox using an OpenFileDialog and then I convert the image to a Base64 string using a MemoryStream and store that string into a list. When loading an image from the list, the image is converted from Base64 string back into an image using a MemoryStream and loaded into the picturebox.

Question: In order for animated GIFs to animate in the picturebox, I must leave the MemoryStream open. Otherwise the animated GIF won't animate. But every time I load a new image into the picturebox, I create a new instance of MemoryStream. By loading images this way without closing their associated MemoryStreams, I assume that my app will leave a bunch of leftover MemoryStreams from all the images that are no longer displayed in the picturebox. I want to keep my app's memory usage low by closing any MemoryStreams that are no longer needed, but I can't close a MemoryStream inside the function where it is created without affecting the current image's animation.

解决方案



这篇关于何时可以关闭用于在C#中的PictureBox控件中支持GIF动画的MemoryStream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:29