Exemplo n.º 1
0
        private async Task UWP(MediaFile file)
        {
            StorageFile inputFile = await StorageFile.GetFileFromPathAsync(file.Path);

            using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                ColorThief.ColorThief ct = new ColorThief.ColorThief();
                var xxxx = ct.GetColor(decoder);
                int a    = 5;
            }
        }
Exemplo n.º 2
0
        private async Task UWP(MediaFile file)
        {
            try
            {
                using (IRandomAccessStream stream = file.GetStream().AsRandomAccessStream())
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                    ColorThief.ColorThief ct = new ColorThief.ColorThief();
                    var xxxx = ct.GetColor(decoder);
                    int a    = 5;
                }
            }
            catch (Exception ex)
            {
                int a = 5;
            }
        }
Exemplo n.º 3
0
        public App()
        {
            // The root page of your application

            var takePhoto = new Button()
            {
                Text = "GetPhoto"
            };
            var image = new Image();

            takePhoto.Clicked += async(sender, args) =>
            {
                MediaFile file;

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    file = await CrossMedia.Current.PickPhotoAsync();
                }
                else
                {
                    file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        Directory = "Sample",
                        Name      = "test.jpg"
                    });
                }


                if (file == null)
                {
                    return;
                }



                image.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    //file.Dispose();
                    return(stream);
                });



#if ANDROID
                var bitmap1 = Android.Graphics.BitmapFactory.DecodeStream(file.GetStream());
                //var bitmap1 = Android.Graphics.BitmapFactory.DecodeFile(file.Path);
                ColorThief.ColorThief ct = new ColorThief.ColorThief();
                var xxxx = ct.GetColor(bitmap1);
                int a    = 5;
#elif WINDOWS_UWP
                UWP(file);
#endif
            };


            MainPage = new ContentPage {
                Content = new StackLayout {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        new Label {
                            HorizontalTextAlignment = TextAlignment.Center,
                            Text = "Welcome to Xamarin Forms!"
                        },
                        takePhoto,
                        image
                    }
                }
            };
        }
Exemplo n.º 4
0
 public void Image2()
 {
     var colorThief = new ColorThief.ColorThief();
     var bitmap     = (Bitmap)Image.FromFile("test2.jpg");
     var rezule     = colorThief.GetColor(bitmap);
 }