Example #1
0
        public async Task <string> GetPicMainColor(StorageFile storageFile, StackPanel StatisticsGrid)
        {
            WriteableBitmap wb           = new WriteableBitmap(1600, 1600);
            string          mainColorHex = "#000000";

            StorageFile file = storageFile;

            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
                    }
                }

                mainColorHex = ColorMatch.GetMajorColor(wb, StatisticsGrid).ToString();  //这个颜色带不透明度的。。
            }
            return(mainColorHex);
        }