使用JPEG文件更改桌面壁纸

4

我正在尝试编写一个简单的程序来更改我的桌面壁纸。 我正在使用下载的jpeg文件,并希望在代码中进行转换。 问题是位图需要为24位才能显示。 我该怎么做呢? 提前致谢。

public class ChangeWallpaper
{
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

    public static void Main()
    {
        Bitmap wallbm = new Bitmap("pic.jpg");
        wallbm.Save("pic.bmp");
        SystemParametersInfo(20, 0, "pic.bmp", 0x01 | 0x02);
    }
}

这显然是针对某个版本的Windows,但你可能需要澄清并标记它。这将有助于更熟悉此主题的人找到并回答您的问题。 - Dolph
2个回答

2

出于某种原因,我无法让克隆功能正常工作。 通过反复尝试,我使用了以下代码成功实现了克隆:

public class ChangeWallpaper
{
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

    public static void Main()
    {
        Bitmap bm = new Bitmap(Image.FromFile("pic.jpg"));
        bm.Save("pic.bmp", ImageFormat.Bmp);
        SystemParametersInfo(20, 0, "pic.bmp", 0x01 | 0x02);
    }
}

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接