我想从visual studio单个文件中截取完整代码的屏幕截图。 有可能吗?
如果是,怎么样?
答案 0 :(得分:2)
打印到类似PDF编写器的东西?或'Microsoft Office Document Image Writer'?
认为这是可行的方法。
答案 1 :(得分:2)
你可以试试这个
- 文件
- 打印
- 选择打印机名称为Microsoft XPS Document Writer
- 按OK
醇>
答案 2 :(得分:2)
要支持颜色,您可以将代码粘贴到一个巨大的RichTextBox(或使用NumericUpDowns来控制宽度和高度的常规尺寸),并有一个按钮可以执行:
var bitmap = new Bitmap(this.richTextBox1.Width, this.richTextBox1.Height);
this.richTextBox1.DrawToBitmap(bitmap, new Rectangle(Point.Empty, bitmap.Size));
bitmap.Save("code.bmp");
旧版(不支持颜色):
var allCode = "...copy all of the code into here";
var font = new Font("Arial", 13);
SizeF size;
using (var g = Graphics.FromImage(new Bitmap(1, 1)))
{
size = g.MeasureString(allCode, font);
}
var bitmap = new Bitmap((int)size.Width + 20, (int)size.Height + 20);
using (var g = Graphics.FromImage(bitmap))
{
g.DrawString(allCode, font, Brushes.Black, 10, 10);
}
bitmap.Save("code.bmp");
答案 3 :(得分:0)
您可以使用此:
Bitmap BmpScreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics ScreenShot = Graphics.FromImage(BmpScreen);
ScreenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
string file = "C:\\test.jpg";
BmpScreen.Save(file, System.Drawing.Imaging.ImageFormat.Png);
是必需的:using System.Drawing;