【问题标题】:C# WPF - How to Save a Screenshot of your Program's Interface's Current View?C# WPF - 如何保存程序界面当前视图的屏幕截图?
【发布时间】:2016-12-18 02:44:58
【问题描述】:

我正在尝试在我的程序中添加一个名为“保存当前快照”的选项,将程序界面的图片保存到所需位置。这仅供参考,例如如果有人不想打开程序来查看他们已经收集的结果。

我已经有了程序截图功能,只是不知道怎么实现,用SaveFileDialog来保存图片。

截图功能:

private static BitmapSource CopyScreen()
        {
            using (var screenBmp = new Bitmap(
                (int)SystemParameters.PrimaryScreenWidth,
                (int)SystemParameters.PrimaryScreenHeight,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                using (var bmpGraphics = Graphics.FromImage(screenBmp))
                {
                    bmpGraphics.CopyFromScreen(0, 0, 0, 0, screenBmp.Size);
                    return Imaging.CreateBitmapSourceFromHBitmap(
                        screenBmp.GetHbitmap(),
                        IntPtr.Zero,
                        Int32Rect.Empty,
                        BitmapSizeOptions.FromEmptyOptions());
                }
            }
        }

SaveFileDialog 代码:

SaveFileDialog saveImage = new SaveFileDialog();
saveImage.Filter = "Images|*.png;*.bmp;*.jpg";
saveImage.ShowDialog();

有人可以帮我将图像保存到用户选择的位置吗? 谢谢。

【问题讨论】:

标签: wpf screen screenshot savefiledialog


【解决方案1】:

您可以在注释中使用引用的代码。

使用保存对话框获取所需的路径,并按照@Zack 的评论进行操作

// If the file name is not an empty string open it for saving.
if(saveImage.FileName != "")
{
    System.IO.FileStream fs = System.IO.File.Open(saveImage.FileName, System.IO.FileMode.OpenOrCreate);
    Screenshot.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
    fs.Close();
}

我正在打电话,所以不能检查这个,如果你有问题,请评论

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    相关资源
    最近更新 更多