如何在c#.net windows应用程序中捕获特定面板的图像? [英] How to capture image of a specific panel in c# .net windows application?

查看:64
本文介绍了如何在c#.net windows应用程序中捕获特定面板的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何在c#.net windows应用程序中按下特定面板按钮时捕获图像?



请帮帮我。



在此先感谢。



Ankit Agarwal
软件工程师

Hello,

How to capture image on button click of a specific panel in c# .net windows application?

Please Help Me.

Thanks in Advance.

Ankit Agarwal
Software Engineer

推荐答案

参考



c-how-to-take-a-screenshot-of-a-portion-of -screen [ ^ ]


从.NET FrameWork 2.0开始,您可以使用Graphics.CopyFromScreen方法,这样可以轻松实现。
Beginning with .NET FrameWork 2.0, you have the Graphics.CopyFromScreen method that makes this easy.
// required in addition to the usual Win Forms stuff
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

// path to the Desktop
private string deskTopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

// counter for number of snaps
private int snapCount = 0;

private void SaveControlImage(Control theControl)
{
    snapCount ++;

    Bitmap controlBitMap = new Bitmap(theControl.Width, theControl.Height);
    Graphics g = Graphics.FromImage(controlBitMap);
    g.CopyFromScreen(PointToScreen(theControl.Location), new Point(0,0), theControl.Size);

    // example of saving to the desktop
    controlBitMap.Save(deskTopPath + @"/snap_" + snapCount.ToString() + @".png", ImageFormat.Png);
}

// assume this is the Click EventHandler for a Button on a Form,
// and that a Panel named 'YourPanelName is what you want to copy
// the screen-image of, and save to a file
private void SnapShotControl_Click(object sender, EventArgs e)
{
    SaveControlImage(YourPanelName);
}


这篇关于如何在c#.net windows应用程序中捕获特定面板的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆