c# - How to draw a screenshot "preview" window? -


i have winforms application user uses take region based screenshot. want have small preview pane, i'm not sure how it. far tried recreating bitmap on mouse move , way laggy usable. thought if used pre-defined image (screenshot of whole screen) , moved inside picturebox based off mouse location zoomed in @ screen (to select precise pixels want take screenshot easier). i'm not sure how can implement this, pretty new drawing show have now.

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:

here mock requested:

the black part of image panel, of course text being label , area see image (stack overflow) picturebox (called zoombox) lines on top of zoombox guide , 2 lines intersect mouse position. hope better assist understand issue.

alt text

another thing might explain issue form fills entire screen "false desktop". picturebox covers entire screen screenshot of desktop when "printscreen" pressed. want little "preview pane" zoomed in location of mouse is.

this little bit laggy, worth try:

it's winforms app in single file showing how "live" zoom might work. doesn't paint cross hairs etc. that's you.

key parts:

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

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -