[英]Change Desktop Wallpaper using a Jpeg file
I'm trying to write a simple program to change my desktop wallpaper. 我正在尝试编写一个简单的程序来更改我的桌面墙纸。 I'm using a downloaded jpeg file and I would like to convert it in code.
我正在使用下载的jpeg文件,我想将其转换为代码。 The problem is the bitmap needs to be 24 bit to display.
问题是位图需要显示为24位。 How do I do this?
我该怎么做呢? Thanks in advance.
提前致谢。
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);
}
}
I couldn't get Clone to work for some reason. 由于某种原因,我无法让Clone工作。 I was able to get it to work by trial and error by using the following code:
通过使用以下代码,我能够通过反复试验使它正常工作:
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);
}
}
使用Bitmap.Clone()
方法并指定所需的像素格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.