简体   繁体   English

C#图片框位图

[英]c# picturebox bitmaps

I have a picturebox that upon request, I save the current display to a bitmap. 我有一个图片框,可根据要求将当前显示内容保存到位图。

My question is, how do I then load that same bitmap to the picturebox? 我的问题是,如何将相同的位图加载到图片框?

Thanks. 谢谢。

EDIT: 编辑:

The only relevant code is: pictureBox1.DrawToBitmap(test1,pictureBox1.ClientRectangle); 唯一相关的代码是:pictureBox1.DrawToBitmap(test1,pictureBox1.ClientRectangle);

The picture box contains graphics that I have written 'freehand' using the mouse. 图片框包含我用鼠标“徒手”写的图形。 So you can use the mouse to write directly onto the screen when the left mouse is pressed. 因此,当您按下鼠标左键时,您可以使用鼠标直接在屏幕上书写。

You can assign any image to the picture box that you want during run-time. 您可以将任何图像分配给运行时期间所需的图片框。 Just set the Image property of the picture box to the picture you want to be displayed. 只需将图片框的Image属性设置为您要显示的图片即可。

For example, to display an image in a picture box from a file on your hard drive, you could use something like: 例如,要在硬盘驱动器上的文件中显示图片框中的图像,您可以使用以下内容:

myPicBox.Image = Image.FromFile("C:\savedimage.bmp");

Or, your edit suggests that you have a bitmap object in memory that you want to display in the picture box. 或者,您的编辑建议您在内存中有一个要在图片框中显示的位图对象。 In that case, it's a simple matter of assigning that bitmap object to the Image property: 在这种情况下,只需将位图对象分配给Image属性即可:

myPicBox.Image = test1;  //(where test1 is your bitmap object in memory)


Edit: Just in case you want to save the bitmap object that you created in memory to disk so that you can reload and use it later, check out the Save method of the Bitmap object: 编辑:如果您想将在内存中创建的位图对象保存到磁盘上,以便以后可以重新加载和使用它,请签出Bitmap对象的Save方法:

test1.Save("C:\savedimage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

如果我没有弄错的话,图片框应该有一个Image属性,你只需用它来分配Bitmap。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM