2010-12-01 7 views
5

私は、ユーザーがリージョンベースのスクリーンショットを取るために使用するWinformsアプリケーションを持っています。私は小さなプレビューペインを持っていたいが、私はそれを行う方法がわからない。これまでは、マウスの動きでビットマップを作り直してみましたが、ちょっと遅すぎて使用できませんでした。だから私は、私は事前定義された画像(画面全体のスクリーンショット)を使用し、あなたが画面にズームを取得するように(あなたが取るしたい正確なピクセルを選択するために、より簡単にスクリーンショット)。私はどのように私はこれを実装することができるか分からない、私はまた、かなり私はあなたが今持っていることを示すように描画にはかなり新しいです。スクリーンショット「プレビュー」ウィンドウを描画する方法は?

private void falseDesktop_MouseMove(object sender, MouseEventArgs e) 
    { 
     zoomBox.Image = showZoomBox(e.Location); 
     zoomBox.Invalidate(); 
    } 

private Image showZoomBox(Point curLocation) 
     { 
      int x = 0; 
      int y = 0; 
      if (curLocation.X - 12 <= 0) 
      { 
       x = curLocation.X - 12; 
      } 
      else 
      { 
       x = curLocation.X; 
      } 

      if (curLocation.Y - 11 <= 0) 
      { 
       y = curLocation.Y - 11; 
      } 
      else 
      { 
       y = curLocation.Y; 
      } 

      Point start = new Point(curLocation.X - 12, curLocation.Y - 11); 
      Size size = new Size(24, 22); 
      Rectangle rect = new Rectangle(start, size); 
      Image selection = cropImage(falseDesktop.Image, rect); 
      return selection; 
     } 

private static Image cropImage(Image img, Rectangle cropArea) 
    { 
     if (cropArea.Width != 0 && cropArea.Height != 0) 
     { 
      Bitmap bmpImage = new Bitmap(img); 
      Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); 
      bmpImage.Dispose(); 
      return (Image)(bmpCrop); 
     } 
     return null; 
    } 

EDIT:

この画像の黒い部分がパネルで、もちろんテキストはあなたが画像を見ラベルや領域である:要求されたようにここで

はモックアップであります(スタックオーバーフロー)はpicturebox(zoomBoxと呼ばれる)になります。zoomBoxの上の線はガイドになり、2本の線が交差する部分はマウスの位置になります。これが私の問題を理解するのに役立つよりよい援助であることを願っています。私の問題を説明するのに役立つかもしれない

alt text

もう一つは、フォームが実際に「偽デスクトップ」を画面全体に表示されています。 "printscreen"が押されたときにデスクトップのスクリーンショットで画面全体を覆うピクチャボックス。だから、私はこの小さな "プレビューペイン"を、基本的にはマウスがどこにあるかのズームインされた場所にしたい。

+0

あなたの問題は、面白い聞こえるかもしれませんが、コードスニペットから、あなたの意図を把握するのは難しいです。続行する最善の方法は、MS Paintを使用してモックアップを作成して、自分が行っていることを示すことができる、IMOです。 (モックアップ画像をアップロードしてリンクする必要があります...) –

+0

@Paul:私はあなたのために詳細とモックアップ画像を追加しました。 – Alex

+0

私はあなたに役立つ完全なコードサンプルを追加しました。ハードコーディングされていて、ちょっとハックされていますが、役に立つかもしれません。 –

答えて

2

これは少しラグが、試してみる価値はある:-)ホイール改革これはTeboScreen: Basic C# Screen Capture
大きな助けになるはずです。

それはどのように示す1つのファイルにWinFormsのアプリだが「ライブ」ズームが機能するかもしれません。それはあなた次第である十字線などを塗ることはありません。

キーパーツ:

  • _scale
  • PictureBoxSizeMode.StretchImage

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

static class Program { 
[STAThread] 
static void Main() { 
    Application.EnableVisualStyles(); 
    Application.SetCompatibleTextRenderingDefault(false); 
    Application.Run(new Form1()); 
} 
} 

public class Form1 : Form { 
private Bitmap _myImage = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\LightHouse.jpg"); 
private int _scale = 10; // keep this < 15 

private PictureBox pboxMain; 
private PictureBox pboxZoom; 
private System.ComponentModel.IContainer components; 

public Form1() { 
    InitializeComponent(); 
} 

private void Form1_Load(object sender, EventArgs e) { 
    pboxMain.Image = _myImage; 
} 

private void pboxMain_MouseMove(object sender, MouseEventArgs e) { 
    try { 
     Rectangle rc = new Rectangle(
      new Point(e.X - _scale, e.Y - _scale), 
      new Size(_scale * 2, _scale * 2)); 
     pboxZoom.Image = _myImage.Clone(rc, PixelFormat.DontCare); 
    } 
    catch (OutOfMemoryException ex) {/* ignore... */} 
} 

protected override void Dispose(bool disposing) { 
    if (disposing && (components != null)) { 
     components.Dispose(); 
    } 
    base.Dispose(disposing); 
} 

private void InitializeComponent() { 
    this.pboxMain = new PictureBox(); 
    this.pboxZoom = new PictureBox(); 
    ((System.ComponentModel.ISupportInitialize)(this.pboxMain)).BeginInit(); 
    ((System.ComponentModel.ISupportInitialize)(this.pboxZoom)).BeginInit(); 
    this.SuspendLayout(); 

    this.pboxMain.Dock = DockStyle.Fill; 
    this.pboxMain.Location = new System.Drawing.Point(0, 0); 
    this.pboxMain.Name = "pboxMain"; 
    this.pboxMain.Size = new System.Drawing.Size(767, 435); 
    this.pboxMain.TabIndex = 0; 
    this.pboxMain.TabStop = false; 
    this.pboxMain.MouseMove += new MouseEventHandler(this.pboxMain_MouseMove); 

    this.pboxZoom.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), 
    ((int)(((byte)(255)))), ((int)(((byte)(192))))); 
    this.pboxZoom.BorderStyle = BorderStyle.FixedSingle; 
    this.pboxZoom.Location = new System.Drawing.Point(12, 12); 
    this.pboxZoom.Name = "pboxZoom"; 
    this.pboxZoom.Size = new System.Drawing.Size(106, 83); 
    this.pboxZoom.SizeMode = PictureBoxSizeMode.StretchImage; 
    this.pboxZoom.TabIndex = 1; 
    this.pboxZoom.TabStop = false; 

    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
    this.AutoScaleMode = AutoScaleMode.Font; 
    this.ClientSize = new System.Drawing.Size(767, 435); 
    this.Controls.Add(this.pboxZoom); 
    this.Controls.Add(this.pboxMain); 
    this.Name = "Form1"; 
    this.Text = "Form1"; 
    this.Load += new System.EventHandler(this.Form1_Load); 
    ((System.ComponentModel.ISupportInitialize)(this.pboxMain)).EndInit(); 
    ((System.ComponentModel.ISupportInitialize)(this.pboxZoom)).EndInit(); 
    this.ResumeLayout(false); 
} 
} 
0

なぜ

+0

私はすでにプログラムされているし、それは本当にうまく動作します:) – Alex

関連する問題