欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c#不使用系统api实现可以指定区域屏幕截屏功能

程序员文章站 2024-02-24 22:55:10
复制代码 代码如下://截取全屏图象        private void btnfullscree...

复制代码 代码如下:

//截取全屏图象
        private void btnfullscreen_click(object sender, eventargs e)
        {
            //创建图象,保存将来截取的图象
            bitmap image = new bitmap(screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height);
            graphics imggraphics = graphics.fromimage(image);
            //设置截屏区域
            imggraphics.copyfromscreen(0, 0, 0, 0, new size(screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height));
            //保存
            saveimage(image);
        }

//保存图象文件
        private void saveimage(image image)
        {
            if (savefiledialog.showdialog(this) == dialogresult.ok)
            {
                string filename = savefiledialog.filename;
                string extension = path.getextension(filename);
                if (extension == ".jpg")
                {
                    image.save(filename, imageformat.jpeg);
                }
                else
                {
                    image.save(filename, imageformat.bmp);
                }
            }
        }