另一个进程使用的图像

时间:2013-03-02 15:25:04

标签: c# image bitmap

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

               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
        {

        }
    }

0 个答案:

没有答案