本文整理汇总了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;
}