2010-12-01 31 views
5

Kullanıcının bölge tabanlı ekran görüntüsü almak için kullandığı bir Winform uygulaması var. Küçük bir önizleme panosuna sahip olmak istiyorum, ancak nasıl yapılacağından emin değilim. Şimdiye kadar fare hareketi üzerinde bir bitmap yeniden yaratmayı denedim ve kullanılabilir olması için çok fazla laggy. Bu yüzden önceden tanımlı bir görüntü kullandım (tüm ekranın ekran görüntüsü) ve farenin bulunduğu yere göre bir resim kutusu içine aldırdım, böylece ekranda yakınlaştırılmış bir görüntü elde edersiniz (istediğiniz pikselleri seçmek için). ekran görüntüsü daha kolay). Bunu nasıl uygulayacağımı bilmiyorum, ayrıca çizim yapmak için de oldukça yeni ve şimdi elimde olanı göstereceğim.Ekran görüntüsü "önizleme" penceresi nasıl çizilir?

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; 
    } 

DÜZENLEME: İşte

sahte yukarı gibidir istendi:

bu resmin siyah kısmı elbette metin Görselin bir etiket ve alan olmak bir paneldir (yığın taşması), zoombox'ın üstündeki çizgilerin (zoombox olarak adlandırılır), bir kılavuz olacak ve 2 çizginin kesiştiği yerde fare konumu olacaktır. Umarım bu, sorunumu anlamanıza yardımcı olacak daha iyi bir yardımcıdır. sorunumu açıklanmasına yardımcı olabilir

alt text

Başka bir şey formu aslında bir "yanlış masaüstü" ile tüm ekranı doldurur olduğunu. "printscreen" düğmesine basıldığında masaüstünün ekran görüntüsüyle tüm ekranı kaplayan bir resim kutusu. Bu yüzden, bu küçük "önizleme bölmesi" nin, farenin nerede olduğuyla ilgili olarak yakınlaştırılmasını istiyorum.

+0

Senin sorunun ilginç geliyor ama kod parçacığı adresinin niyet anlamaya zor. Devam etmenin en iyi yolu, neyin peşinde olduğunuzu göstermek için MS Paint ile bir maket oluşturmaktır, IMO. (Sen-ebilmek almak ve mock-up pic için bağlantı gerekir ...) –

+0

@Paul: Ben daha fazla ayrıntı ve sizin için bir sahte görüntü ekledim. – Alex

+0

Size yardımcı olabilecek eksiksiz bir kod örneği ekledim. Bu kodlanmış ve biraz hack-ish ama sizin için yararlı olabilir. –

cevap

2

:-) Wheel, ama değer bir deneyin yeniden icat Neden
:

Tek dosyada bir Win app gösteren bulunuyor "canlı" bir zoom çalışabilir. Bu sana bağlı olan çapraz kılları vb.

Anahtar Parçalar:

  • _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); 
} 
} 
İlgili konular