Ошибка "A generic error occurred in GDI+" - C#

Узнай цену своей работы

Формулировка задачи:

В сишарпе не силен, что не так? ошибка: An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll Additional information: A generic error occurred in GDI+. в этой строке:
Листинг программы
  1. tempImage.SaveAsFile(@"C:\full.png", ImageFormat.Png);
код:
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.Threading.Tasks;
  8. using OpenQA.Selenium;
  9. using OpenQA.Selenium.Firefox;
  10. using OpenQA.Selenium.Chrome;
  11. using OpenQA.Selenium.Support.UI;
  12. using OpenQA.Selenium.Remote;
  13. using OpenQA.Selenium.Interactions;
  14. using DeathByCaptcha;
  15. using System.IO; // для работы с файлами
  16. using System.Threading; // для пауз
  17. using System.Net; // для скачки капчи
  18. using System.Diagnostics; // для отслеживания процессов
  19. namespace driver
  20. {
  21. class Program
  22. {
  23. public static Bitmap CropImage(Bitmap source, Rectangle section)
  24. {
  25. Bitmap bmp = new Bitmap(section.Width, section.Height);
  26. Graphics g = Graphics.FromImage(bmp);
  27. g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
  28. return bmp;
  29. }
  30. static void Main(string[] args)
  31. {
  32. IWebDriver driver = new ChromeDriver();
  33. //replace with the page you want to navigate to
  34. string your_page = "https://www.google.com";
  35. driver.Navigate().GoToUrl(your_page);
  36. ITakesScreenshot ssdriver = driver as ITakesScreenshot;
  37. Screenshot screenshot = ssdriver.GetScreenshot();
  38. Screenshot tempImage = screenshot;
  39. tempImage.SaveAsFile(@"C:\full.png", ImageFormat.Png);
  40. //replace with the XPath of the image element
  41. IWebElement my_image = driver.FindElement(By.XPath("//*[@id="hplogo"]/canvas[1]"));
  42. Point point = my_image.Location;
  43. int width = my_image.Size.Width;
  44. int height = my_image.Size.Height;
  45. Rectangle section = new Rectangle(point, new Size(width, height));
  46. Bitmap source = new Bitmap(@"C:\full.png");
  47. Bitmap final_image = CropImage(source, section);
  48. final_image.Save(@"C:\image.jpg");
  49. }
  50. }
  51. }

Решение задачи: «Ошибка "A generic error occurred in GDI+"»

textual
Листинг программы
  1. tempImage.SaveAsFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "full.png"), ImageFormat.Png);

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы