scree のスナップショットをキャプチャし、キャプチャしたときに動的に表示する Windows フォーム アプリケーションを開発しようとしています。また、キャプチャした画像を削除する機能も提供したいと考えています。現在、それらをキャプチャしてサムネイルとして表示するまで完了しています。特定のサムネイルをクリックすると、画像の拡大版が表示されます。キャプチャした画像のリンクとリサイズ版の表示がうまくいきません。ここに私がこれまでに行ったことの私のコードがあります。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using HotKeys;
namespace Snapper
{
public partial class SnapperForm : Form
{
static int imgCounter = 0;//keeps track of img for naming
//create an instance of GlobalHotKey
private GlobalHotKey ghk1;
private GlobalHotKey ghk2;
public SnapperForm()
{
InitializeComponent();
//pass the required key combination and form to the constructor
ghk1 = new GlobalHotKey(Constants.CTRL + Constants.SHIFT, Keys.S, this);
ghk2 = new GlobalHotKey(Constants.CTRL + Constants.SHIFT, Keys.W, this);
}
private Keys GetKey(IntPtr LParam)
{
return (Keys)((LParam.ToInt32()) >> 16);
}
//Perform the action required when HotKey is pressed
protected override void WndProc(ref Message m)
{
if (m.Msg == Constants.WM_HOTKEY_MSG_ID)
{
switch (GetKey(m.LParam))
{
case Keys.S:
//take a snapshot of entire screen when CTRL + SHIFT + S is pressed
CaptureScreen();
break;
case Keys.W:
TestHotKeyCSW();
break;
}
}
base.WndProc(ref m);
}
private void TestHotKeyCSW()
{
MessageBox.Show("Hot key CTRL + SHIFT + W recived");
}
private void CaptureScreen()
{
/*This method captures a snapshot of screen and
* adds it to the ImageFlowLayoutPanel
*/
Rectangle bounds = Screen.GetBounds(Point.Empty);
Bitmap bmp = new Bitmap(bounds.Width,bounds.Height);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
imgCounter += 1;
bmp.Save("snap" + imgCounter.ToString() + ".jpg", ImageFormat.Jpeg);
//working with ImageList
CapturedImagesList.Images.Add(bmp);
PictureBox tempPictureBox = new PictureBox();
//generates a thumbnail image of specified size
tempPictureBox.Image = bmp.GetThumbnailImage(100, 100,
new Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
tempPictureBox.Size = new System.Drawing.Size(100, 100);
tempPictureBox.Click += new EventHandler(this.tempPictureBox_Click);
ImageFlowLayoutPanel.Controls.Add(tempPictureBox);
}
//This click event will be used to display the enlarged images
private void tempPictureBox_Click(object sender, EventArgs e)
{
PreviewPictureBox.Image = ((PictureBox)sender).Image;
}
public bool ThumbnailCallback()
{
return true;
}
private void Main_Load(object sender, EventArgs e)
{
if (!ghk1.Register() || !ghk2.Register())
{
MessageBox.Show("Failed to register", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SnapperForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (!ghk1.Unregister() || !ghk2.Unregister())
{
MessageBox.Show("Failed to UnRegister", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
キャプチャした画像をイメージリストに保存し、動的に生成されたサムネイル (画像ボックス) 間で同期し、プレビュー画像ボックスでクリックされた画像の拡大バージョンを表示することを考えました。flowlayoutpanel から previewpicturebox にクリックすると画像を表示できますが、サムネイルのサイズしか表示されません。画像を拡大したい。誰でも私の要件を達成するために私を導くことができますか? この設計が不可能な場合、このアプリケーションに適切なコントロールを使用する方法を教えてくれる人はいますか? 前もって感謝します。