using _SCREEN_CAPTURE;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace ryCommon._SCREEN_CAPTURE
{
    /// <summary>
    /// 
    /// </summary>
    public class ScreenCapture
    {
        private FrmCapture m_frmCapture;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bitmap"></param>
        /// <returns></returns>
        public static Bitmap DeepCopyBitmap(Bitmap bitmap)
        {
            try
            {
                Bitmap dstBitmap = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), bitmap.PixelFormat);
                return dstBitmap;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : {0}", ex.Message);
                return null;
            }
        }
        /// <summary>
        /// 开始截图
        /// </summary>
        /// <param name="IsCaptureCursor">是否截取鼠标指针</param>
        /// <returns></returns>
        public Bitmap StartCapture(bool IsCaptureCursor)
        {
            if (m_frmCapture == null || m_frmCapture.IsDisposed)
                m_frmCapture = new FrmCapture();
            m_frmCapture.IsCaptureCursor = IsCaptureCursor;
            m_frmCapture.ShowDialog();
            if(m_frmCapture.IsCapture)
            {
                Bitmap bit = DeepCopyBitmap(m_frmCapture.m_bmpLayerCurrent);
                m_frmCapture.m_bmpLayerCurrent.Dispose();
                return bit;
            }
            return null;
        }
    }
}
