0

我正在获取计算机的屏幕截图,然后通过复制它然后使用它来将其设置为图片框,但是在第一次这样做之后,它说图片正在被另一个进程使用,但我猜我只是笨拙的。

               public void UpdatePic()
    {
        String newtemp = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\screentemp.png";
        if (File.Exists(newtemp)) { File.Delete(newtemp); }
        File.Copy(screendirect, newtemp);
        Image image = Image.FromFile(newtemp);
        try
        {
            using (Bitmap tempBitmap = new Bitmap(image))
            {
                Size size = new Size(pictureBox1.Width, pictureBox1.Height);
                Bitmap backgroundBitmap = new Bitmap(size.Width, size.Height);
                using (Graphics g = Graphics.FromImage(backgroundBitmap))
                {
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    // Get the set of points that determine our rectangle for resizing.
                    Point[] corners = { new Point(0, 0), new Point(backgroundBitmap.Width, 0), new Point(0, backgroundBitmap.Height)};
                    g.DrawImage(tempBitmap, corners);
                    g.Dispose();
                }
                pictureBox1.Image = backgroundBitmap;

            }
        }
        finally
        {

        }
    }
4

0 回答 0