小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C#截圖操作方法大全

 羊玉wngbx 2020-11-09
using System.Drawing;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    class ScreenCapture
    {
        private Bitmap _screenshot = null;
 
        /// <summary>
        /// 截取全屏
        /// </summary>
        /// <returns>返回值</returns>
        public Bitmap CaptureScreen()
        {
            return Capture(Rectangle.Empty, false);
        }
 
        /// <summary>
        /// 截取全屏并保存
        /// </summary>
        /// <param name="fileName">文件路徑</param>
        /// <returns></returns>
        public Bitmap CaptureScreen(string fileName)
        {
            Bitmap screenshot = Capture(Rectangle.Empty, false);
            saveImage(fileName, screenshot);
            return screenshot;
        }
 
        /// <summary>
        /// 截屏到剪切板
        /// </summary>
        public void CopyToClipboard()
        {
            if (this._screenshot != null)
                Clipboard.SetImage(this._screenshot);
            else if (this._screenshot == null)
                MessageBox.Show("No screenshot found. Please take a screenshot first.", "Copy to Clipboard");
        }
 
        /// <summary>
        /// 區(qū)域截屏
        /// </summary>
        /// <param name="rect">區(qū)域范圍</param>
        /// <returns>返回值</returns>
        public Bitmap CaptureRectangle(Rectangle rect)
        {
            return Capture(rect, true);
        }
 
        /// <summary>
        /// 區(qū)域截屏
        /// </summary>
        /// <param name="rect">區(qū)域范圍</param>
        /// <param name="fileName">文件路徑</param>
        /// <returns>返回值</returns>
        public Bitmap CaptureRectangle(Rectangle rect, string fileName)
        {
            Bitmap screenshot = Capture(rect, true);
            saveImage(fileName, screenshot);
            return screenshot;
        }
 
        private Bitmap Capture(Rectangle rect, bool isRect)
        {
            int screenWidth = Screen.PrimaryScreen.Bounds.Width;
            int screenHeight = Screen.PrimaryScreen.Bounds.Height;
 
            Bitmap screenshot = null;
 
            if(!isRect)
                screenshot = new Bitmap(screenWidth, screenHeight);
            else if(isRect)
                screenshot = new Bitmap(rect.Width, rect.Height);
 
            Graphics g = Graphics.FromImage(screenshot);
            if (!isRect)
            {
                g.CopyFromScreen(Point.Empty, Point.Empty, screenshot.Size);
            }
            else if (isRect)
            {
                g.CopyFromScreen(new Point(rect.X, rect.Y), Point.Empty, rect.Size);
            }
 
            this._screenshot = screenshot;
 
            return screenshot;
        }
 
        private void saveImage(string fileName, Bitmap screenshot)
        {
            string ext = System.IO.Path.GetExtension(fileName);;
            ext = ext.ToLower();
 
            if (ext == ".jpg" || ext == ".jpeg")
                screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
            else if(ext == ".gif")
                screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Gif);
            else if(ext == ".png")
                screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            else if (ext == ".bmp")
                screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
            else if (ext == ".tiff")
                screenshot.Save(fileName, System.Drawing.Imaging.ImageFormat.Tiff);
        }
    }
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多