Good day to all, comrades!
As part of the functionality of my application is the change of desktop wallpaper. With the help of Google, I found a popular solution in the C # programming language.
I attach the full class code below.
namespace BingPhotoOfTheDay.etc { static class bing { [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern Int32 SystemParametersInfo( UInt32 action, UInt32 uParam, String vParam, UInt32 winIni); private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14; private static readonly UInt32 SPIF_UPDATEINIFILE = 0x01; private static readonly UInt32 SPIF_SENDWININICHANGE = 0x02; public static string GetURLToImage() { WebClient client = new WebClient(); client.DownloadFile("http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US", "parse.xml"); XmlDocument xDoc = new XmlDocument(); xDoc.Load("parse.xml"); XmlElement xRoot = xDoc.DocumentElement; string URL = ""; XmlNode node = xDoc.DocumentElement.SelectSingleNode("/images/image/urlBase"); URL = node.InnerText + "_1920x1080.jpg"; return URL; } public static void DownloadImage() { WebClient client = new WebClient(); client.DownloadFile("https://bing.com" + GetURLToImage(), "image.jpg"); Bitmap bitmap = (Bitmap)Image.FromFile("image.jpg"); bitmap.Save("image.bmp"); } public static void SetWallpaper() { SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "image.bmp", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } } }
However, I observe a problem with a call of the given function. The program works without errors, however, instead of the expected result of changing the wallpaper, I get black wallpaper.
Unfortunately I do not know which way to dig.
I ask for help