Beispiel #1
0
        public async Task InitAsync()
        {
            // NEEDS BT VERIFICATION IF THIS STILL HAPPENS: check if there is a MeTile to grab (otherwise you get an exception
            // that will also kill the BT connection for daring to read to far beyond the Stream)
            // Need to find a workaround, since this is not exposed in the new lib: var tileId = _client.GetMeTileId();

            BandImage meTileImage = null;

            try
            {
                meTileImage = await _client.PersonalizationManager.GetMeTileImageAsync();
            }
            catch (InvalidOperationException)
            { } // no background image

            if (meTileImage != null)
            {
                _background = meTileImage.ToWriteableBitmap();
            }


            _themeColor = await _client.PersonalizationManager.GetThemeAsync();

            SetColorProperties();

            // Notify that all properties have changed
            NotifyPropertyChanged(null);

            _inited = true;
        }
        public async Task SetMeTileImageAsync(BandImage image)
        {
#if __ANDROID__
            await Native.SetMeTileImageTaskAsync(image.ToBitmap());
#elif __IOS__
            await Native.SetMeTileImageTaskAsync(image.ToUIImage().ToBandImage());
#elif WINDOWS_PHONE_APP
            await Native.SetMeTileImageAsync(image.ToWriteableBitmap().ToBandImage());
#endif
        }
Beispiel #3
0
        private async void SetGetMeTileImage_Click(object sender, RoutedEventArgs args)
        {
            IBandInfo[] pairedBands;
            IBandClient client = null;

            this.viewModel.StatusMessage = "Running Me Tile image demo ...";

            // Enumerate Bands that are paired to this device.
            pairedBands = await BandClientManager.Instance.GetBandsAsync();

            if (pairedBands.Length == 0)
            {
                this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                return;
            }

            try
            {
                // Connect to the first Band in the enumeration.
                client = await BandClientManager.Instance.ConnectAsync(pairedBands[0]);
            }
            catch (Exception e)
            {
                this.viewModel.StatusMessage = "Failed to connect to a Band.\r\n" + e.Message;
                return;
            }

            using (client)
            {
                // Get the custom image from storage, and convert it to a BandImage.
                WriteableBitmap meTileBitmap = await LoadImage("ms-appx:///Assets/SampleMeTileImage.jpg");

                BandImage meTileImage = meTileBitmap.ToBandImage();

                // Set the MeTile image on the band.
                await client.PersonalizationManager.SetMeTileImageAsync(meTileImage);

                // Read the MeTile image back from the band.
                meTileImage = await client.PersonalizationManager.GetMeTileImageAsync();

                // Convert the image back to a WritableBitmap.
                meTileBitmap = meTileImage.ToWriteableBitmap();

                // Display the image on screen.
                this.MeTileImage.Source = meTileBitmap;

                // To clear the MeTile image on the Band, set it to null.
                // await client.PersonalizationManager.SetMeTileImageAsync(null);
            }

            this.viewModel.StatusMessage = "Done.";
        }
Beispiel #4
0
        /// <summary>
        /// Returns MeTile from Microsoft Band
        /// </summary>
        /// <returns></returns>
        public static async Task <WriteableBitmap> Get_Image()
        {
            BandClient = await Connect_Band(await Get_Band());

            if (BandClient == null)
            {
                return(new WriteableBitmap(1, 1));
            }

            using (BandClient)
            {
                BandImage bandImage = await BandClient.PersonalizationManager.GetMeTileImageAsync();

                return(bandImage.ToWriteableBitmap());
            }
        }
Beispiel #5
0
 /// <summary>
 /// 画像の変換
 /// </summary>
 /// <param name="image">画像情報</param>
 /// <returns>画像ソース</returns>
 public static StreamImageSource FromNative(BandImage image)
 {
     return((StreamImageSource)ImageSource.FromStream(() => image.ToWriteableBitmap().PixelBuffer.AsStream()));
 }