失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 小创意之-设置电脑壁纸

小创意之-设置电脑壁纸

时间:2021-09-22 13:34:05

相关推荐

小创意之-设置电脑壁纸

小创意— 设置电脑壁纸

看着面黄肌肉的电脑壁纸,默默打卡了百度,搜索美丽的壁纸。看着风格古怪,分辨率里五五六六的图片。默默的流了几滴汗。于是单生了一个念头,为什么不抓去合适的图片自动设置成电脑壁纸呢?于是便用C#写了一个小程序。

寻找合适的代码图片下载到本地

提供几个常见的图片网址

https://unsplash.it/1600/900?random(国外的随机图片)

/api/pictures/random/?key=BingEverydayWallpaperPicture(必应每日图片)

/api/pictures/random(随机图片)

通过C#下载图片和预览图片

// 图片下载下来 保存到本地string url = "/api/pictures/random/";.WebClient mywebclient = new .WebClient();mywebclient.DownloadFile(url, filePath);// this.pictureBox1.Load(filePath);// 把图片预览在C#的 pictureBox控件FileStream pFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);pictureBox1.Image = Image.FromStream(pFileStream);pFileStream.Close();pFileStream.Dispose();

调用win的库 设置为壁纸

/// <summary>/// 图片设置为背景图片/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){ MessageBox.Show(filePath);SystemParametersInfo(20,1,filePath,1);}[DllImport("user32.dll",EntryPoint= "SystemParametersInfo")]public static extern int SystemParametersInfo(int uAction,int uParam,string lpvParam,int fuWinIni);}

最后样式

窗体设置样式

运行效果

具体的代码在github连接里面

小创意— 设置电脑壁纸

看着面黄肌肉的电脑壁纸,默默打卡了百度,搜索美丽的壁纸。看着风格古怪,分辨率里五五六六的图片。默默的流了几滴汗。于是单生了一个念头,为什么不抓去合适的图片自动设置成电脑壁纸呢?于是便用C#写了一个小程序。

寻找合适的代码图片下载到本地

提供几个常见的图片网址

https://unsplash.it/1600/900?random(国外的随机图片)

/api/pictures/random/?key=BingEverydayWallpaperPicture(必应每日图片)

/api/pictures/random(随机图片)

通过C#下载图片和预览图片

// 图片下载下来 保存到本地string url = "/api/pictures/random/";.WebClient mywebclient = new .WebClient();mywebclient.DownloadFile(url, filePath);// this.pictureBox1.Load(filePath);// 把图片预览在C#的 pictureBox控件FileStream pFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);pictureBox1.Image = Image.FromStream(pFileStream);pFileStream.Close();pFileStream.Dispose();

调用win的库 设置为壁纸

/// <summary>/// 图片设置为背景图片/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){ MessageBox.Show(filePath);SystemParametersInfo(20,1,filePath,1);}[DllImport("user32.dll",EntryPoint= "SystemParametersInfo")]public static extern int SystemParametersInfo(int uAction,int uParam,string lpvParam,int fuWinIni);}

最后样式

窗体设置样式

运行效果

具体的代码在github连接里面

如果觉得《小创意之-设置电脑壁纸》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。