LoginSignup
0
2

More than 3 years have passed since last update.

画面キャプチャ画像を連続して文書に貼れるように、画面に常駐するキャプチャーツールを作った

Last updated at Posted at 2020-03-19

windowsには、snipping toolという、画面キャプチャがあって、画面の一部分をクリッピングできるが、連続で切り抜いて、文書にぺたぺた貼っていくような場面には向かないので、csharpで、画面に常駐するクリッピングツールをつくった

scr_cap.cs

//コンパイルは、コマンドラインから以下
//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:winexe scr_cap.cs

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;


namespace scr_cap
{
  public class Form1 : Form
  {
    public Button button1;
    public Form1()
    {
      this.Text = "scr_cap";
      this.TransparencyKey = this.BackColor;
      this.TopMost = true;
      //this.SizeGripStyle = 1;
      this.FormBorderStyle = FormBorderStyle.Sizable;

      button1 = new Button();
      button1.Size = new Size(30, 1000);
      button1.Location = new Point(0, 0);
      button1.Text = "-";
      this.Controls.Add(button1);
      button1.Click += new EventHandler(button1_Click);
    }

    private void button1_Click(object sender, EventArgs e)
    {

  try
  {
    var r = this.ClientRectangle;
    var bmp = new Bitmap(r.Width-30, r.Height, PixelFormat.Format32bppArgb);
    var g = Graphics.FromImage(bmp);
    var iSource = this.PointToScreen(new Point(30, 0));
    var iDestination = new Point(0, 0);

    g.CopyFromScreen(
      iSource, iDestination,
      this.ClientSize, CopyPixelOperation.SourceCopy);
    //bmp.Save(".\\capture.png", ImageFormat.Png);
    Pen redPen = new Pen(Color.Red, 1);
    Rectangle rect = new Rectangle(0, 0, bmp.Width-1,bmp.Height-1);
    g.DrawRectangle(redPen, rect);


    Clipboard.SetDataObject(bmp, true, 20, 500);
  }
  catch(Exception ex)
  {
    MessageBox.Show("エラー:\n\n" + ex);//
  }

    }
    [STAThread]
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.Run(new Form1());
    }
  }
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2