Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9509

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

$
0
0

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

scr_cap.cs
//コンパイルは、コマンドラインから以下//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:winexe scr_cap.csusingSystem;usingSystem.Windows.Forms;usingSystem.Drawing;usingSystem.Drawing.Imaging;namespacescr_cap{publicclassForm1:Form{publicButtonbutton1;publicForm1(){this.Text="scr_cap";this.TransparencyKey=this.BackColor;this.TopMost=true;//this.SizeGripStyle = 1;this.FormBorderStyle=FormBorderStyle.Sizable;button1=newButton();button1.Size=newSize(30,1000);button1.Location=newPoint(0,0);button1.Text="-";this.Controls.Add(button1);button1.Click+=newEventHandler(button1_Click);}privatevoidbutton1_Click(objectsender,EventArgse){try{varr=this.ClientRectangle;varbmp=newBitmap(r.Width-30,r.Height,PixelFormat.Format32bppArgb);varg=Graphics.FromImage(bmp);variSource=this.PointToScreen(newPoint(30,0));variDestination=newPoint(0,0);g.CopyFromScreen(iSource,iDestination,this.ClientSize,CopyPixelOperation.SourceCopy);//bmp.Save(".\\capture.png", ImageFormat.Png);PenredPen=newPen(Color.Red,1);Rectanglerect=newRectangle(0,0,bmp.Width-1,bmp.Height-1);g.DrawRectangle(redPen,rect);Clipboard.SetDataObject(bmp,true,20,500);}catch(Exceptionex){MessageBox.Show("エラー:\n\n"+ex);//}}[STAThread]staticvoidMain(){Application.EnableVisualStyles();Application.Run(newForm1());}}}

Viewing all articles
Browse latest Browse all 9509

Trending Articles