• 抓取屏幕或窗体并保存成图片


    抓取屏幕:
    rectangle r = system.windows.forms.screen.primaryscreen.bounds;  
    image img = new bitmap(r.width, r.height);  
    graphics g = graphics.fromimage(img);  
    g.copyfromscreen(new point(0, 0), new point(0, 0), new size(r.width, r.height));。  
    intptr dc = g.gethdc(); 
    g.releasehdc(dc);  
    g.dispose();  
    img .save("c:a.jpg");  
    或  
    private static extern bool bitblt(intptr hdcdest,int nxdest,int nydest,int nwidth,int nheight,intptr hdcsrc,int nxsrc,int nysrc,int32 dwrop);  

    private image catchscreen()
    {
    bitmap bmpcatched = new bitmap(this.tablelayoutpanel1.width + 1, this.tablelayoutpanel1.height + 1);
    graphics g = graphics.fromimage(bmpcatched);
    system.drawing.rectangle rect = new system.drawing.rectangle(10, 10, 500, 400);
      g.copyfromscreen(new point(this.left + this.tablelayoutpanel1.location.x + 7, this.tablelayoutpanel1.location.y + (panelregisted.height - tablelayoutpanel1.height) / 2 - 1), new point(0, 0), this.panelregisted.clientrectangle.size);
      g.drawrectangle(new pen(color.black), 0, 0, bmpcatched.width - 1, bmpcatched.height - 1);
      image image = bmpcatched; 
      return image;
      }

    保存窗体或控件:
         Rectangle r = Screen.PrimaryScreen.Bounds;
                Bitmap bmp = new Bitmap(r.Width,r.Height);
                this.DrawToBitmap(bmp, r);
                bmp.Save("d:/aa.jpg");
        注:窗体及控件皆有DRAWTOBITMAP这个方法(FW2.0以上)。

  • 相关阅读:
    ansible
    celery 计划任务使用
    11 session 使用
    10 模版继承和页面之间的调用
    9 模版语言 jinja2
    8 公共函数
    7 文件上传
    6 获取请求头和URL信息
    5 获取Form表单取值
    4 文件操作 支持图片 视频 mp3 文本等
  • 原文地址:https://www.cnblogs.com/vic_lu/p/1820581.html
Copyright © 2020-2023  润新知