C#使用Bitmap截图

1.做path

    string CurrentPath = Environment.CurrentDirectory;
    string imageName = CurrentPath + @"\" + GetImageName();
private string GetImageName()
{
    if (!File.Exists("Image"))
    {
        Directory.CreateDirectory("Image");
    }
    string time = DateTime.Now.ToString("hh-mm-ss");
    return @"Image\" + time + ".bmp";
}

2.按需截图

private void Screenshot()
{
string CurrentPath = Environment.CurrentDirectory;
string imageName = CurrentPath + @“” + GetImageName();
//综下所诉,可以完成大部分截图需求,截图截不全跟分辨率有关

    //这个很鸡肋,要pictureBox上有才行,要是有的话我直接Save了,干嘛还搞这些
    //Bitmap bitmap = new Bitmap(this.Width,this.Height);
    //pictureBox1.DrawToBitmap(bitmap, new Rectangle(0, panel1.Height, panel2.Width, panel2.Height));
    //Image image = bitmap;
    //image.Save(imageName);

    //截图指定区域,这里是pictureBox1区域
    //Image objImage = new Bitmap(this.Width, this.Height);
    //Graphics gd = Graphics.FromImage(objImage);
    //Point f = this.PointToScreen(new Point(panel2.Left, panel2.Top));//这个应该是距离窗口之间的距离
    //gd.CopyFromScreen(f, new Point(0, 0), new Size(pictureBox1.Width, pictureBox1.Height));//起始一个point,target2个point,target的起始点定点为source
    //objImage.Save(imageName);

    //截全屏
    //int x = Screen.AllScreens[0].Bounds.Size.Width;
    //int y = Screen.AllScreens[0].Bounds.Size.Height;
    //Image image = new Bitmap(x, y);
    //Graphics g = Graphics.FromImage(image);
    //g.CopyFromScreen(0,0, 0, 0, new Size(x, y));
    //image.Save(imageName);
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值