Une erreur générique s'est produite dans GDI+
Bonjour,
J'ai la même erreur GDI que dans ce post ici
Citation:
Une erreur générique s'est produite dans GDI+.
Sauf que mon problème est un peut différent, je n'utilise pas un filestream donc je ne sais pas comment et si je doit fermer quelquechose...
Mon programme fait un screenshot de ou des écrans à intervale régulier (60s dans mon cas).
J'utilise donc un thread que je suspend pendant 60s et je ré-écrase l'ancien screenshot avec le nouveau.
Voiçi le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
foreach (Screen s in Screen.AllScreens)
{
bmpSS = new Bitmap(s.Bounds.Width,
s.Bounds.Height,
PixelFormat.Format32bppArgb);
gfxSS = Graphics.FromImage(bmpSS);
gfxSS.CopyFromScreen(
s.Bounds.X,
s.Bounds.Y,
0,
0,
s.Bounds.Size,
CopyPixelOperation.SourceCopy);
//ajout de la date de creation du fichier
Font drawFont = new Font("Arial", 30);
gfxSS.DrawString(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), drawFont, Brushes.LawnGreen, 0, 0);
//sauvegarde fichier
if (Properties.Settings.Default.format == "png")
{
if (s == Screen.PrimaryScreen)
bmpSS.Save(AutoScreenShot.Properties.Settings.Default.path + "\\" + "autoscreenshot_screen1.png", ImageFormat.Png);
else
bmpSS.Save(AutoScreenShot.Properties.Settings.Default.path + "\\" + "autoscreenshot_screen2.png", ImageFormat.Png);
}
else if (Properties.Settings.Default.format == "jpeg")
{
if (s == Screen.PrimaryScreen)
bmpSS.Save(AutoScreenShot.Properties.Settings.Default.path + "\\" + "autoscreenshot_screen1.jpg", ImageFormat.Jpeg);
else
bmpSS.Save(AutoScreenShot.Properties.Settings.Default.path + "\\" + "autoscreenshot_screen2.jpg", ImageFormat.Jpeg);
}
bmpSS = null;
gfxSS = null;
}
Thread.Sleep(AutoScreenShot.Properties.Settings.Default.interval*1000); |
Merci d'avance