7

C# を使用してスクリーンショットを撮り、アプリケーションの特定のコンテナー/部分の写真を撮るように制限する方法を知っている人はいますか? アプリケーションの画面全体またはウィンドウ全体は必要ありません。

私のパネルは単に呼び出されます: panel1 ユーザーは「ボタン」をクリックし、panel1 のスクリーンショットを撮り、電子メールに添付します。

そのセクションのみのスクリーン ショットを撮り、C:\ ドライブにローカルに保存するか、Outlook の電子メールに添付または埋め込みたいと考えています。

私はインターネットで他のさまざまなことを読みましたが、それらのほとんどは、私が探していない Web ブラウザー コントロールのスクリーンショットを撮る際に複雑な変更を作成することに対処しなければなりませんでした。

4

6 に答える 6

5

私は次のようなものを使用してこれを行います

public static void TakeCroppedScreenShot(
    string fileName, int x, int y, int width, int height, ImageFormat format)
{
    Rectangle r = new Rectangle(x, y, width, height);
    Bitmap bmp = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppArgb);
    Graphics g = Graphics.FromImage(bmp);
    g.CopyFromScreen(r.Left, r.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
    bmp.Save(fileName, format);
}

これが役立つことを願っています

于 2013-04-14T15:21:43.603 に答える
3

Asifの回答の改善:

public static Bitmap takeComponentScreenShot(Control control)
{
    // find absolute position of the control in the screen.
    Rectangle rect=control.RectangleToScreen(control.Bounds);

    Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
    Graphics g = Graphics.FromImage(bmp);

    g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);

    return bmp;
}
于 2015-03-28T09:57:58.847 に答える
1

コントロールをビットマップとして保存するためにこれを見つけました:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private void Button1_Click(object sender, EventArgs e)
    {
        SaveAsBitmap(panel1,"C:\\path\\to\\your\\outputfile.bmp");
    }

    public void SaveAsBitmap(Control control, string fileName)
    {   
        //get the instance of the graphics from the control
        Graphics g = control.CreateGraphics();

        //new bitmap object to save the image
        Bitmap bmp = new Bitmap(control.Width, control.Height);

        //Drawing control to the bitmap
        control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height));

        bmp.Save(fileName);
        bmp.Dispose();

    }
}

ここでOutlook に関する情報を見つけましたが、自分の PC に Outlook がインストールされていないため、テストできませんでした。

于 2013-04-14T15:32:01.010 に答える