Publish a small open source software, Bing daily wallpaper.
The small software can automatically get Bing's beautiful picture set as wallpaper, and support randomly switch historical wallpaper, view wallpaper story.
Welcome to download use, point star! If you have any questions, please leave a message or mention issue.
Open Source Address: Github.com/jadepeng/bing-wallpaper, want to know the technical principle of see technical solutions
How to use
The program does not have the main window, is the tray program, click on the tray icon, the operation of the relevant menu.
Functional characteristics
- Automatically get Bing's latest pictures and set as wallpaper
- Wallpapers story, you can also view the story behind the wallpaper
- Historical wallpaper, support viewing wallpapers for the last two years
- Random switch, randomly get a few years of wallpaper, shuttle time among
- Timed switch, automatically switch on the wallpaper every hour after opening
Wallpaper Story
You can also view the story behind the wallpaper to support up and down switching
Random switching
Once clicked, it randomly selects one of the historical data and displays
Timed switchover
When turned on, it automatically switches every 1 hours, which is the equivalent of auto-click Random Switch.
Development origins
After aware of the discovery, Sogou wallpaper Assistant has closed the service, can not get new wallpaper, recall Bing daily provide beautiful pictures, so consider writing a gadget, you can automatically get pictures from Bing and set as wallpaper.
Usage Self-compiling
git clone github.com/jadepeng/bing-wallpaper.git
.../BingWallpaper/bin/Release/BingWallpaper.exe
Download binary
Download the latest build package from release, the author is Win10 X64. You cannot run the compilation of your own download code.
Compatibility
This is works on Windows systems.
I ' ve tested it on Windows 7 and Windows Ten as an Admin user. If you face any problems the open an issue!
Technical Solution Interface
github.com/kompiuter/bing-wallpaper
Already have a prototype, so based on this modification can meet the requirements. So fork this project directly.
The first is the new data problem, the http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US
interface can get the data in JSON format. Where IDX can be adjusted to get up to 10 days of data.
{"images": [{"startdate": "20180819","fullstartdate": "201808191600","enddate": "20180820","url": "/az/hprichbg/rb/PineMartenScotland_ZH-CN10077017107_1920x1080.jpg","urlbase": "/az/hprichbg/rb/PineMartenScotland_ZH-CN10077017107","copyright": "凯恩戈姆山国家公园里的一只松貂,苏格兰 ( SCOTLAND: The Big Picture/Minden Pictures)","copyrightlink": "http://www.bing.com/search?q=%E6%9D%BE%E8%B2%82&form=hpcapt&mkt=zh-cn","quiz": "/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20180819_PineMartenScotland%22&FORM=HPQUIZ","wp": true,"hsh": "997ecf7cb73e47b55617ce44f1097373","drk": 1,"top": 1,"bot": 1,"hs": []}],"tooltips": {"loading": "正在加载...","previous": "上一个图像","next": "下一个图像","walle": "此图片不能下载用作壁纸。","walls": "下载今日美图。仅限用作桌面壁纸。"}}
Then you can cn.bing.com/cnhp/coverstory/
get the wallpaper story by:
{"date": "August 20","title": "鼠类终结者","attribute": "英国,凯恩戈姆山国家公园","para1": "凯恩戈姆山国家公园坐落于苏格兰高地中心地区,是英国最大的国家公园。喜欢刺激的人将这里视为天堂,苏格兰的五个滑雪胜地中有三座位于这里,此外这里还有两处水上活动中心、进行飞钓和跟踪雄鹿的区域。这里也是景观壮丽的野生区域,内有水獭、獾、红松鼠、鹿以及鹗等。你瞧,那粗壮的树干后面还藏着一个可爱的小家伙——松貂,它无忧无虑的在这里生存着!","para2": "","provider": " SCOTLAND: The Big Picture/Minden Pictures","imageUrl": "http://hpimges.blob.core.chinacloudapi.cn/coverstory/watermark_pinemartenscotland_zh-cn10077017107_1920x1080.jpg","primaryImageUrl": "http://hpimges.blob.core.chinacloudapi.cn/coverstory/watermark_pinemartenscotland_zh-cn10077017107_1920x1080.jpg","Country": "英国","City": "凯恩戈姆山国家公园","Longitude": "-3.538737","Latitude": "57.037787","Continent": "欧洲","CityInEnglish": "Cairngorms National Park","CountryCode": ""}
Therefore, the two interfaces can be called to obtain the latest day of data.
As mentioned above, Bing's interface can only get 10 days of data, and only get 1 days of wallpaper story, it needs to be obtained from other sources. By searching, it is easy to find bing.ioliu.cn/has more than two years of data, we can crawl down as offline data, so that the data is all.
Through the self-developed crawler platform, simple configuration under:
Download to get 898 data, should contain more than 2 years of data:
Export as JSON and put into the project.
Set Wallpaper
To set the wallpaper, you need to call the SystemParametersInfo method in User32.dll,
public sealed class Wallpaper {const int spi_setdeskwallpaper = 20; const int spif_updateinifile = 0x01; const int spif_sendwininichange = 0x02; [DllImport ("user32.dll", CharSet = CharSet.Auto)] static extern int SystemParametersInfo (int uaction, int uparam, S Tring Lpvparam, int fuwinini); Public enum Style:int {tiled, centered, stretched} public static void Set (Image img, style style) {string temppath = Path.Combine (Path.gettemppath (), "wallpaper.bmp"); Img. Save (TempPath, SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.BMP); RegistryKey key = Registry.CurrentUser.OpenSubKey (@ "Control Panel\Desktop", true); if (style = = style.stretched) {key. SetValue (@ "Wallpaperstyle", 2.ToString ()); Key. SetValue (@ "Tilewallpaper", 0.ToString ()); } if (style = = style.centered) { Key. SetValue (@ "Wallpaperstyle", 1.ToString ()); Key. SetValue (@ "Tilewallpaper", 0.ToString ()); } if (style = = style.tiled) {key. SetValue (@ "Wallpaperstyle", 1.ToString ()); Key. SetValue (@ "Tilewallpaper", 1.ToString ()); } var a = SystemParametersInfo (spi_setdeskwallpaper, 0, TempPath, Spif_updateinifile | Spif_sendwininichange); } }
Wallpaper Story
A simple WinForm page, background is a picture, left and right two images as buttons, a panel below shows the details.
Random switching
The program starts by loading the historical data from the JSON and putting it in a list, randomly getting one from the inside.
static string datafile = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "History.json"); static string bakdatafile = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "History.json.bak"); Static Historyimageprovider () {historyimages = Loadhistoryimages (); Historyimages.foreach (image = {Date2image.add (image). Date, image); }); } static list
New Data Save After the new data is fetched from the interface, it is added to the list and persisted to the hard disk.
public static void AddImage (Historyimage image) {if (Date2image.containskey (image). Date) {historyimages.add (image); Date2image.add (image. Date, image); Save (); }} public static void Save () {if (file.exists (datafile)) { File.delete (Bakdatafile); File.move (datafile, bakdatafile); } try {using (var stream = new FileStream (datafile, FileMode.Create)) {var ser = new DataContractJsonSerializer (typeof (Historyimage)); var line = System.Text.Encoding.UTF8.GetBytes ("\ r \ n"); Historyimages.foreach (image = {ser. WriteObject (stream, image); Stream. Write (line, 0, line. Length); }); } }catch {if (file.exists (Bakdatafile)) {file.copy (Bakdatafile, datafile); } } }
Jadepeng
Source: Jqpeng's technical notepad--http://www.cnblogs.com/xiaoqi
Your support is the greatest encouragement to bloggers, thank you for your serious reading.
This article is copyrighted by the author, welcome, but without the consent of the author must retain the statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.