スクリーンショットをImageコントロールに表示する
こちらの記事を参考にさせていただきました!すごい!できた! 参考にといいつつ毎回まるパクリですすみません。
【WPF】 スクリーンショットを撮り続けて動画に保存する - 旅行好きなソフトエンジニアの備忘録
C#でBitmapで描いた画像をImageコントロールに表示してみた
private void Button_Click_2(object sender, RoutedEventArgs e) { var bmp = GetScreenShot(640, 480); // 表示 IntPtr hbitmap = bmp.GetHbitmap(); imageArea.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); DeleteObject(hbitmap); } [System.Runtime.InteropServices.DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr hObject); private Bitmap GetScreenShot(int width, int height) { var resizedBmp = new Bitmap(width, height); using (var bmp = new Bitmap((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight)) using (var g = System.Drawing.Graphics.FromImage(bmp)) using (var resizedG = System.Drawing.Graphics.FromImage(resizedBmp)) { // スクリーンショットを撮る g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), bmp.Size); resizedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear; resizedG.DrawImage(bmp, 0, 0, width, height); } return resizedBmp; }