我得到的是类似于截图制作应用程序的东西。(设法序列化,感谢上帝!!!)单击按钮时,通过访问处理类的方法截取屏幕截图。现在棘手的部分是该类有另一种操作上述结果的方法,其方式不同于调用相应的处理方法时,创建(显示)一个窗口并且位图图像应该进入显示容器那个窗口。问题是到目前为止,我注意到在 WPF 中,图像控件的源不能归因于存储图像的变量。我如何显示存储在该变量中的图像而不必先保存它,获取 uri 等。?
问问题
6573 次
2 回答
5
您需要从内存流创建图像,这已被许多人详细记录。这里有两个链接可以帮助您入门:
于 2010-02-23T22:15:03.073 回答
2
感谢链接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% :)
于 2010-02-24T09:58:59.653 回答