保存打印屏幕在C# [英] Save print screen in C#
本文介绍了保存打印屏幕在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
位图位图=新位图(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
显卡显卡= Graphics.FromImage(位图图片排列);
graphics.CopyFromScreen(0,0,0,0,bitmap.Size);
bitmap.Save(@C:\Temp\printscreen.jpg,ImageFormat.Jpeg);
这是我的打印屏幕按钮的代码。问题是,我按下按钮几次,它只是写在旧映像文件(printscreen.jpg),它不会产生另一个新的图像文件,如printscreen1.jpg。
解决方案
它不会产生另一种新的图像文件
您并没有要求它创建一个,你的代码
位图。保存(@C:\Temp\printscreen.jpg,ImageFormat.Jpeg);
总是被写入同一个文件。
新的图像文件,如printscreen1.jpg
块引用>
如果你想创建一个新的文件,你需要的生成的文件名,动态即可。类似
字符串文件名= System.IO.Path.GetTempPath()+ DateTime.Now.ToString()+.JPG
bitmap.Save(文件名,ImageFormat.Jpeg);
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics graphics = Graphics.FromImage(bitmap as Image); graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size); bitmap.Save(@"C:\Temp\printscreen.jpg", ImageFormat.Jpeg);
This is my code for print screen button. The problem is that I press the button few times and it just write over the old image file (printscreen.jpg), it will not create another new image file such as printscreen1.jpg.
解决方案it will not create another new image file
You are not asking it to create one, your code
bitmap.Save(@"C:\Temp\printscreen.jpg", ImageFormat.Jpeg);
is always writing to the same file.
new image file such as printscreen1.jpg
If you want to create a new file, you need to generate your filename dynamically. Something like
string fileName = System.IO.Path.GetTempPath() + DateTime.Now.ToString() + ".jpg"; bitmap.Save(fileName, ImageFormat.Jpeg);
这篇关于保存打印屏幕在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文