コード例 #1
0
            public static async Task GetBingTheme()
            {
                try
                {
                    var httpclient = new System.Net.Http.HttpClient();
                    var picbytes   = await httpclient.GetByteArrayAsync("http://appserver.m.bing.net/BackgroundImageService/TodayImageService.svc/GetTodayImage?dateOffset=0&urlEncodeHeaders=true&osName=windowsPhone&osVersion=8.10&orientation=480x800&deviceName=WP8&mkt=en-US");

                    var picfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Theme/Skin/Bing/background.jpg"));

                    await FileIO.WriteBytesAsync(picfile, picbytes);

                    WriteableBitmap wb = new WriteableBitmap(1000, 1500);
                    await wb.SetSourceAsync(await picfile.OpenAsync(FileAccessMode.Read));

                    var bingtheme = new BingThemeData();
                    bingtheme.BackgroundColor  = GetColor.GetMajorColor(wb);
                    bingtheme.BackgroundColor1 = Color.FromArgb(190, bingtheme.BackgroundColor.R, bingtheme.BackgroundColor.G, bingtheme.BackgroundColor.B);
                    var rgb = bingtheme.BackgroundColor.R * 0.299 + bingtheme.BackgroundColor.G * 0.587 + bingtheme.BackgroundColor.B * 0.114;
                    bingtheme.BackgroundColor2 = bingtheme.BackgroundColor;
                    if (rgb >= 192)
                    {
                          {
                            bingtheme.Foreground      = Colors.White;
                            bingtheme.Front1          = Colors.White;
                            bingtheme.Front2          = Color.FromArgb(255, 185, 185, 185);
                            bingtheme.List_Background = Color.FromArgb(100, 103, 103, 103);
                        }
                    }
                    else
                    {
                        bingtheme.Foreground      = Colors.White;
                        bingtheme.Front1          = Colors.Black;
                        bingtheme.Front2          = Color.FromArgb(255, 124, 124, 124);
                        bingtheme.List_Background = Color.FromArgb(180, 255, 255, 255);
                    }
                    string xamlstring = await PathIO.ReadTextAsync("ms-appx:///Theme/BingTemp.txt");

                    xamlstring = String.Format(xamlstring, bingtheme.BackgroundColor.ToString(), bingtheme.BackgroundColor1.ToString(), bingtheme.BackgroundColor2.ToString(), bingtheme.Foreground.ToString(), bingtheme.Front1.ToString(), bingtheme.Front2.ToString(), bingtheme.List_Background.ToString());
                    var xamlfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Theme/BingTheme.xaml"));

                    await FileIO.WriteTextAsync(xamlfile, xamlstring);
                }
                catch (Exception)
                {
                    await new MessageDialog("无网络连接!").ShowAsync();
                }
            }
コード例 #2
0
        private async void ThemeList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var list = sender as GridView;

            if (list.SelectedItem != null)
            {
                var data = list.SelectedItem as Theme;
                if (data.id == 4)
                {
                    Process.IsActive = true;
                    await BingThemeData.GetBingTheme();

                    Process.IsActive = false;
                }
                Class.Setting.Theme.NowTheme = data.theme;
                ShowDialog();
                list.SelectedIndex = -1;
                init();
            }
        }