当前位置: 首页>>代码示例>>C#>>正文


C# WriteableBitmap.ToBandImage方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.ToBandImage方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.ToBandImage方法的具体用法?C# WriteableBitmap.ToBandImage怎么用?C# WriteableBitmap.ToBandImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.ToBandImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateBandWallpaper

        /// <summary>
        /// Updates the band wallpaper
        /// </summary>
        /// <param name="file"></param>
        public async Task<bool> UpdateBandWallpaper(StorageFile file)
        {
            try
            {
                IBandInfo pairedBand = await GetPairedBand();
                if (pairedBand == null)
                {
                    // We don't have a band.
                    return true;
                }

                // Try to connect to the band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBand))
                {
                    WriteableBitmap bitmap = null;
                    BandImage newBandImage = null;
                    //byte[] pixelArray = null;
                    using (AutoResetEvent are = new AutoResetEvent(false))
                    {
                        // Get the bitmap on the UI thread.
                        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async () =>
                        {
                            try
                            {
                                // Create a bitmap for the Me Tile image. 
                                // The image must be 310x102 pixels for Microsoft Band 1 
                                // and 310x102 or 310x128 pixels for Microsoft Band 2.  
                                ImageProperties properties = await file.Properties.GetImagePropertiesAsync();
                                bitmap = new WriteableBitmap((int)properties.Width, (int)properties.Height);
                                bitmap.SetSource((await file.OpenReadAsync()));
                                newBandImage = bitmap.ToBandImage();
                                //pixelArray = bitmap.ToByteArray();
                            }
                            catch (Exception) { }
                            are.Set();
                        });
                        are.WaitOne(10000);
                    }

                    // Check if we failed
                    if(bitmap == null || newBandImage == null)
                    {
                        throw new Exception("Failed to make new bitmap image.");
                    }

                    // Try to set the image.
                    await bandClient.PersonalizationManager.SetMeTileImageAsync(newBandImage);

                    //// Compute the average color
                    //Color averageColor = new Color();
                    //uint bAvg = 0;
                    //uint rAvg = 0;
                    //uint gAvg = 0;
                    //uint count = 0;
                    //for (int i = 0; i < pixelArray.Length; i += 4)
                    //{
                    //    rAvg += pixelArray[i + 1];
                    //    gAvg += pixelArray[i + 2];
                    //    bAvg += pixelArray[i + 3];
                    //    count++;
                    //}
                    //averageColor.R = (byte)(rAvg / count);
                    //averageColor.B = (byte)(bAvg / count);
                    //averageColor.G = (byte)(gAvg / count);

                    //BandTheme theme = new BandTheme() { Base = averageColor.ToBandColor() };
                    //await bandClient.PersonalizationManager.SetThemeAsync(theme);
                }
            }
            catch(Exception e)
            {
                m_baconMan.MessageMan.DebugDia("failed to set band wallpaper", e);
                return false;
            }
            return true;
        }
开发者ID:RareNCool,项目名称:Baconit,代码行数:80,代码来源:BackgroundBandManager.cs


注:本文中的Windows.UI.Xaml.Media.Imaging.WriteableBitmap.ToBandImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。