【问题标题】:Is there a way to display a image in WPF stored in memory?有没有办法在存储在内存中的 WPF 中显示图像?
【发布时间】:2011-01-20 06:52:12
【问题描述】:

我得到的是一个截图制作应用程序。 (设法序列化,感谢上帝!!!)单击按钮时,通过访问处理类的方法截取屏幕截图。现在棘手的部分是该类有另一种操作上述结果的方法,其方式不同于调用相应的处理方法时,创建(显示)一个窗口并且位图图像应该进入显示容器那个窗口。问题是到目前为止,我注意到在 WPF 中,图像控件的源不能归因于存储图像的变量。我如何显示存储在该变量中的图像而不必先保存它,获取 uri 等。 ?

【问题讨论】:

    标签: wpf image controls bitmap operations


    【解决方案1】:

    感谢链接 slugster。我是这样做的:

    MemoryStream ms = new MemoryStream();
    sBmp = gBmp; //note: gBmp is a variable that stores the captured image and passes it on to the method that uses sBMP as a distribuitor of the variable holding the captured image data
    //variable that holds image
    sBmp.Save(ms,ImageFormat.Bmp);
    //my buffer byte
    byte[] buffer = ms.GetBuffer();
    //Create new MemoryStream that has the contents of buffer
    MemoryStream bufferPasser = new MemoryStream(buffer);
    //Creates a window with parents classthatholdsthismethod and null
    Edit childEdit = new Edit(this, null);
    childEdit.Show();
    //I create a new BitmapImage to work with
    BitmapImage bitmap = new BitmapImage();
    bitmap.BeginInit();
    bitmap.StreamSource = bufferPasser;
    bitmap.EndInit();
    //I set the source of the image control type as the new BitmapImage created earlier.
    childEdit.imgImageCanvas.Source = bitmap;
    childEdit.Activate();
    

    我基本上将我在这些页面上找到的内容与我找到的一些关于如何将 bmp 传递到 memstream 的信息结合起来。我让这个工作 100% :)

    【讨论】:

      【解决方案2】:

      您需要从内存流创建图像,这已被许多人详细记录。这里有两个链接可以帮助您入门:

      http://forums.silverlight.net/forums/p/44637/166282.aspx

      http://www.wpftutorial.net/Images.html

      【讨论】:

        猜你喜欢
        • 2013-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-06
        • 2016-04-17
        • 1970-01-01
        相关资源
        最近更新 更多