Exemple #1
0
        /// <summary>
        /// 获取图片主颜色
        /// </summary>
        /// <param name="b"></param>
        /// <param name="backgroundBrush"></param>
        /// <returns></returns>
        public static async Task <SolidColorBrush> GetMajorColorAndBlur(byte[] b, ImageBrush backgroundBrush)
        {
            WriteableBitmap wb = new WriteableBitmap(1000, 1500);

            using (IRandomAccessStream iras = b.AsBuffer().AsStream().AsRandomAccessStream())
            {
                await wb.SetSourceAsync(iras);
            }
            //高斯模糊
            BlurEffect be = new BlurEffect(wb);

            backgroundBrush.ImageSource = await be.ApplyFilter(10);//高斯模糊等级可以自己定义

            //取主色调并应用到TagsTextBlock
            return(new SolidColorBrush(GetColor.GetMajorColor(wb)));
        }
        public async void UpdateData()
        {
            nowplay = await Class.Model.Player.GetNowPlay();

            var playlist = await Class.Model.PlayList.GetPlayList();

            if (playlist != null)
            {
                switch (playlist.cyc)
                {
                case Class.Model.PlayList.cycling.单曲循环:
                    Cyc_Btn.Icon = new SymbolIcon(Symbol.RepeatOne);
                    break;

                case Class.Model.PlayList.cycling.列表循环:
                    Cyc_Btn.Icon = new SymbolIcon(Symbol.RepeatAll);
                    break;

                case Class.Model.PlayList.cycling.随机播放:
                    Cyc_Btn.Icon = new SymbolIcon(Symbol.Shuffle);
                    break;

                default:
                    break;
                }
            }
            NowLrc_Text.Text = "";
            if (nowplay != null)
            {
                SongName_Text.Text   = nowplay.title;
                SingerName_Text.Text = nowplay.singername;

                if (nowplay.albumid.Length > 0)
                {
                    var imgurl = await GetAlbumImg(nowplay.albumid);

                    Album_Img.Source = new BitmapImage(new Uri(imgurl));
                    WriteableBitmap wb = new WriteableBitmap(1000, 1500);
                    HttpClient      hc = new HttpClient();
                    byte[]          b  = await hc.GetByteArrayAsync(imgurl);

                    using (IRandomAccessStream iras = b.AsBuffer().AsStream().AsRandomAccessStream())
                    {
                        await wb.SetSourceAsync(iras);
                    }
                    BlurEffect be = new BlurEffect(wb);
                    albumimgbrush = new ImageBrush()
                    {
                        ImageSource = await be.ApplyFilter(2), Stretch = Stretch.UniformToFill
                    };
                    mainGrid.Background = new ImageBrush()
                    {
                        ImageSource = await be.ApplyFilter(2), Stretch = Stretch.UniformToFill
                    };
                }
                else
                {
                    Album_Img.Source = new BitmapImage()
                    {
                        UriSource = new Uri("ms-appx:///Assets/image/albumimg2.png")
                    };
                }
            }
            else
            {
                SongName_Text.Text   = "酷狗音乐";
                SingerName_Text.Text = "传播好音乐";
            }
        }
        private async void init()
        {
            BackgroundMedia       = Class.MediaControl.GetCurrent();
            ProcessTimer.Interval = TimeSpan.FromMilliseconds(800);
            PicTimer.Interval     = TimeSpan.FromSeconds(60);
            PicTimer.Tick        += async(s, e) =>
            {
                if (PlayerFlip.SelectedIndex == 1)
                {
                    if (singerdata != null && singerdata.pics != null && singerdata.pics.Count > 0)
                    {
                        if (picnum == singerdata.pics.Count - 1)
                        {
                            picnum = 0;
                        }
                        else
                        {
                            picnum = picnum + 1;
                        }
                        if (PlayerFlip.SelectedIndex == 1)
                        {
                            WriteableBitmap wb = new WriteableBitmap(1000, 1500);
                            HttpClient      hc = new HttpClient();
                            byte[]          b  = await hc.GetByteArrayAsync(singerdata.pics[picnum].Replace("{size}", "480"));

                            using (IRandomAccessStream iras = b.AsBuffer().AsStream().AsRandomAccessStream())
                            {
                                await wb.SetSourceAsync(iras);
                            }
                            BlurEffect be = new BlurEffect(wb);
                            mainGrid.Background = new ImageBrush()
                            {
                                ImageSource = await be.ApplyFilter(1), Stretch = Stretch.UniformToFill
                            };
                        }
                    }
                }
            };
            ProcessTimer.Tick += async(s, e) =>
            {
                ishander = false;
                var alltime    = BackgroundMedia.NaturalDuration.TotalSeconds;
                var alltime_m  = Math.Floor(alltime / 60);
                var alltime_s  = Math.Floor(alltime % 60);
                var thistime   = BackgroundMedia.Position.TotalSeconds;
                var thistime_m = Math.Floor(thistime / 60);
                var thistime_s = Math.Floor(thistime % 60);
                if (alltime_s < 10)
                {
                    AllTime_Text.Text = alltime_m.ToString() + ":0" + alltime_s.ToString();
                }
                else
                {
                    AllTime_Text.Text = alltime_m.ToString() + ":" + alltime_s.ToString();
                };
                if (thistime_s < 10)
                {
                    ThisTime_Text.Text = thistime_m.ToString() + ":0" + thistime_s.ToString();
                }
                else
                {
                    ThisTime_Text.Text = thistime_m.ToString() + ":" + thistime_s.ToString();
                };
                SongSlider.Maximum = alltime;
                SongSlider.Value   = thistime;
                await Task.Delay(50);

                ishander = true;
            };
            lrcpanel.LrcNowText = NowLrc_Text;
            UpdateData();
            if (BackgroundMedia.CurrentState == MediaPlayerState.Playing)
            {
                PlayBtn.Icon = new SymbolIcon(Symbol.Pause);
                nowplay      = await Class.Model.PlayList.GetNowPlay();

                if (nowplay != null)
                {
                    lrcpanel.LrcNowText = NowLrc_Text;
                    lrcpanel.LoadLrcFromLocal();
                }
                ProcessTimer.Start();
            }
            else
            {
                PlayBtn.Icon = new SymbolIcon(Symbol.Play);
            }
            BackgroundMedia.CurrentStateChanged += BackgroundMedia_CurrentStateChanged;
        }
Exemple #4
0
        private async void DropArea_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                MainColorText.Text = "Loading...";
                var items = await e.DataView.GetStorageItemsAsync();

                //文件过滤,防止他们往里面拖 excel
                // items = items.OfType<StorageFile>().Where(s => s.FileType.Equals(".jpg")).ToList() as IReadOnlyList<IStorageItem>;
                //items = items.OfType<StorageFile>().Where(s => s.FileType.Equals(".png")).ToList() as IReadOnlyList<IStorageItem>;

                //细化一下文件类型,然后对于非法类型做一下提示

                if (items.Count == 0)
                {
                    MainColorText.Text = "Please drag a JPG file in this panel.";
                }


                if (items.Count > 0)
                {
                    var storageFile = items[0] as StorageFile;

                    //设置图片路径
                    ImageBrush  imageBrush = new ImageBrush();
                    BitmapImage bitmap     = new BitmapImage();

                    await bitmap.SetSourceAsync(await storageFile.OpenAsync(FileAccessMode.Read));

                    imageBrush.ImageSource  = bitmap;
                    PriImagePath.Fill       = imageBrush;
                    PriImagePath2.Fill      = imageBrush;
                    TempPanelImg.Fill       = imageBrush;
                    TempPanelImg.Visibility = Visibility.Visible;

                    MainColorText.Text = "Calculating...";

                    //获取主色调
                    ColorAbouts colorAbouts = new ColorAbouts();
                    FileAbouts  fileAbouts  = new FileAbouts();
                    ColorMatch  colorMatch  = new ColorMatch();

                    StorageFile file2 = await fileAbouts.GetPanelPic(TempPanel);

                    string comColor = await colorAbouts.GetPicMainColor(file2, StatisticsGrid);

                    string mainColor = "#" + comColor.Substring(3, 6);
                    TempPanelImg.Visibility = Visibility.Collapsed;

                    //颜色匹配&设置边框
                    int minNub = colorMatch.CompareDist(mainColor);

                    TriditionalColor triditionalColors = new TriditionalColor();
                    TridColor[]      tridColors        = new TridColor[630];
                    tridColors = triditionalColors.InitTriditionalColors();

                    ColorNameTextblock.Text = tridColors[minNub].Name;
                    SolidColorBrush triColor = colorAbouts.GetSolidColorBrush(tridColors[minNub].Hex);
                    ColorBorder.BorderBrush = triColor;

                    MainColorGrid.Background = triColor;

                    //设置时间戳
                    TimeTurn timestamp = new TimeTurn();
                    string   atime     = await timestamp.GetImageProperties(storageFile);

                    TimestampTextBlock.Text = atime;

                    //test
                    TempPanelImg.Visibility = Visibility.Visible;

                    WriteableBitmap wb2           = new WriteableBitmap(1000, 600);
                    string          mainColorHex2 = "#000000";


                    if (file2 != null)
                    {
                        // Set the source of the WriteableBitmap to the image stream
                        using (IRandomAccessStream fileStream2 = await file2.OpenAsync(FileAccessMode.Read))
                        {
                            try
                            {
                                await wb2.SetSourceAsync(fileStream2);

                                System.IO.File.Delete(file2.Path);
                            }
                            catch (TaskCanceledException)
                            {
                                // The async action to set the WriteableBitmap's source may be canceled if the user clicks the button repeatedly
                            }
                        }

                        mainColorHex2 = ColorMatch.GetMajorColor2(wb2).ToString();
                        string mainColor2 = "#" + mainColorHex2.Substring(3, 6);
                        //DisplayText.Text = mainColor2;

                        TimestampTextBlock.Foreground = colorAbouts.GetSolidColorBrush(colorAbouts.InvertColor2(mainColor2));


                        //设置天数
                        TextHelper textHelper = new TextHelper();
                        DaysTextblock.Text = textHelper.CalculateDays().ToString();

                        //设置节气
                        LunarHolDayTextBlock.Text = TextHelper.GetLunarHolDay(DateTime.Now);

                        //设置表情
                        RanTextBlock.Text = textHelper.RandomEmoji();


                        //弥散阴影
                        MainColorText.Text = "Almost Done...";

                        WriteableBitmap wb   = new WriteableBitmap(1600, 1600);
                        StorageFile     file = await fileAbouts.GetPanelPic(PicPanel);

                        if (file != null)
                        {
                            // Set the source of the WriteableBitmap to the image stream
                            using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                            {
                                try
                                {
                                    await wb.SetSourceAsync(fileStream);
                                }
                                catch (TaskCanceledException)
                                {
                                    // The async action to set the WriteableBitmap's source may be canceled if the user clicks the button repeatedly
                                }
                            }

                            //高斯模糊
                            BlurEffect be = new BlurEffect(wb);
                            ShadowImg.Source = await be.ApplyFilter(22);//高斯模糊等级可以自己定义

                            System.IO.File.Delete(file.Path);
                        }

                        MainColorText.Text = "Done!";
                    }
                }
            }
        }