public static void Set(string fpath)
{
string sfiletype = fpath.Substring(fpath.LastIndexOf(".")+1,(fpath.Length-fpath.LastIndexOf(".")-1)).ToLower();
if (sfiletype == "bmp")
{
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, fpath, 1); //调用,filename为图片地址,最后一个参数需要为1,0的话在重启后就变回原来的了
}
else
{
string bmp_path = Application.StartupPath + @"\wallpaper.bmp";
FileInfo file_info = new FileInfo(bmp_path);
if (file_info.Exists)
{
file_info.Delete();
PictureBox picutrebox = new PictureBox();
picutrebox.Image = Image.FromFile(fpath);
picutrebox.Image.Save(bmp_path, ImageFormat.Bmp);
picutrebox.Image.Dispose();
picutrebox.Dispose();
}
else
{
PictureBox picutrebox = new PictureBox();
picutrebox.Image = Image.FromFile(fpath);
picutrebox.Image.Save(bmp_path, ImageFormat.Bmp);
picutrebox.Image.Dispose();
picutrebox.Dispose();
}
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, bmp_path, 1);
}
}