有没有办法在 WPF 中显示存储在内存中的图像?

发布于 2024-08-22 21:38:46 字数 217 浏览 10 评论 0原文

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

What I got is something like a screenshot making application. (managed to serialize, thank god!!!) When a button is clicked a screenshot is taken by accessing a handling classe's method. now the tricky part is that the class has another method for operating with the above said result, in such a manner than when the respective handling method is called, a window is created(shown) and the bitmap image should go into a display container in that window. The problem is that so far, I've noticed that in WPF the image control's source cannot be attribuited to a variable which stores the image. How can i display the image stored in that variable without having to save it first,get uri,etc. ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

年少掌心 2024-08-29 21:38:46

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

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

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

You need to create an image from a memory stream, this has been well documented by many people. Here are two links that may get you started:

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

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

夜访吸血鬼 2024-08-29 21:38:46

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

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 传递到内存流的一些信息结合起来。我让它 100% 工作:)

thanks for the links slugster. Here's how I did it:

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();

I've basically combined what I had found on those pages with some info I found on how to pass on a bmp to a memstream. I got this to work 100% :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文