Exemplo n.º 1
0
        public List <UploadFile> GetFile(string format)
        {
            Process proc;

            if (!Environment.Is64BitProcess)
            {
                proc = Process.Start("C:\\Windows\\sysnative\\SnippingTool.exe", "/clip");
            }
            else
            {
                proc = Process.Start("C:\\Windows\\system32\\SnippingTool.exe", "/clip");
            }

            proc.WaitForExit();

            if (!Clipboard.ContainsImage())
            {
                throw new InvalidOperationException();
            }

            Path = TempFileHandler.RegisterFile();
            string filename = string.Format(format + ".Jpeg", DateTime.Now, "Screenclip");

            Clipboard.GetImage().Save(Path, ImageFormat.Jpeg);

            return(new List <UploadFile> {
                new UploadFile
                {
                    Path = Path,
                    Filename = filename,
                }
            });
        }
Exemplo n.º 2
0
        public List <UploadFile> GetFile(string format)
        {
            int screenLeft   = SystemInformation.VirtualScreen.Left;
            int screenTop    = SystemInformation.VirtualScreen.Top;
            int screenWidth  = SystemInformation.VirtualScreen.Width;
            int screenHeight = SystemInformation.VirtualScreen.Height;

            var Screenshot = new Bitmap(screenWidth,
                                        screenHeight,
                                        PixelFormat.Format32bppArgb);

            using (var graphic = Graphics.FromImage(Screenshot))
            {
                graphic.CopyFromScreen(screenLeft,
                                       screenTop,
                                       0,
                                       0,
                                       Screenshot.Size,
                                       CopyPixelOperation.SourceCopy);
            }

            Path = TempFileHandler.RegisterFile();
            string filename = string.Format(format + ".Jpeg", DateTime.Now, "Screenshot");

            Screenshot.Save(Path, ImageFormat.Jpeg);

            return(new List <UploadFile> {
                new UploadFile
                {
                    Path = Path,
                    Filename = filename,
                }
            });
        }
Exemplo n.º 3
0
 public void FreeFile()
 {
     if (Path is not null)
     {
         TempFileHandler.FreeFile(Path);
     }
 }
Exemplo n.º 4
0
        public List <UploadFile> GetFile(string format)
        {
            if (Clipboard.ContainsFileDropList())
            {
                var UploadList = new List <UploadFile>();

                System.Collections.Specialized.StringCollection FileList = Clipboard.GetFileDropList();

                foreach (string s in FileList)
                {
                    var u = new UploadFile
                    {
                        Path     = s,
                        Filename = string.Format(format, DateTime.Now, System.IO.Path.GetFileName(s)),
                    };
                    UploadList.Add(u);
                }

                return(UploadList);
            }

            if (Clipboard.ContainsImage())
            {
                Path = TempFileHandler.RegisterFile();
                string filename = string.Format(format + ".Jpeg", DateTime.Now, "Clipboard Image");

                Clipboard.GetImage().Save(Path, ImageFormat.Jpeg);

                return(new List <UploadFile> {
                    new UploadFile
                    {
                        Path = Path,
                        Filename = filename,
                    }
                });
            }

            if (useText && Clipboard.ContainsText())
            {
                Path = TempFileHandler.RegisterFile();
                string filename = string.Format(format + ".txt", DateTime.Now, "Clipboard Text");

                File.WriteAllText(Path, Clipboard.GetText());

                return(new List <UploadFile> {
                    new UploadFile
                    {
                        Path = Path,
                        Filename = filename,
                    }
                });
            }

            throw new InvalidOperationException("Please copy something before attmepting to upload from clipboard");
        }
Exemplo n.º 5
0
 public void FreeFile()
 {
     TempFileHandler.FreeFile(Path);
 }