Exemplo n.º 1
0
        async void OnButtonClickedChoosePhotos(object sender, EventArgs e)
        {
            IPicturePicker picturePicker = DependencyService.Get <IPicturePicker>();

            using (Stream stream = await picturePicker.GetImageStreamAsync())
            {
                if (stream != null)
                {
                    loadBitMap = true;
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        stream.CopyTo(memStream);
                        memStream.Seek(0, SeekOrigin.Begin);

                        using (SKManagedStream skStream = new SKManagedStream(memStream))
                        {
                            bitMap = SKBitmap.Decode(skStream);
                        }
                    }
                }
                else
                {
                    loadBitMap = false;
                }
            }
            CallImageActionTools();
        }
Exemplo n.º 2
0
        async Task ExecuteSelectMedia()
        {
            var stream = await picturePicker.GetImageStreamAsync();

            SelectedImage = ImageSource.FromStream(() => stream); //I'm just reading Image, We might have video as well, need to check.

            //These commented lines applied portrait lock on the NextPage, Here on WelcomePage.

            //MessagingCenter.Send<string>(AppOrientation.Portrait.ToString(), "mode");
            //await NavigationService.NavigateAsync("WelcomePage");
        }
Exemplo n.º 3
0
        public async void PickNewImage()
        {
            Stream stream = await picturePicker.GetImageStreamAsync();

            if (stream != null)
            {
                Image image = new Image
                {
                    Source          = ImageSource.FromStream(() => stream),
                    BackgroundColor = Color.Gray
                };

                var abc = 1;
            }
            else
            {
                Console.WriteLine("Stream was null");
            }
        }
Exemplo n.º 4
0
        public BasicBitmapsPage()
        {
            Title = "Basic Bitmaps";

            canvasView = new SKCanvasView();
            canvasView.PaintSurface += OnCanvasViewPaintSurface;
            Content = canvasView;

            // Load web bitmap.
            Uri        uri     = new Uri("http://developer.xamarin.com/demo/IMG_3256.JPG?width=480");
            WebRequest request = WebRequest.Create(uri);

            request.BeginGetResponse((IAsyncResult arg) =>
            {
                try
                {
                    using (Stream stream = request.EndGetResponse(arg).GetResponseStream())
                        using (MemoryStream memStream = new MemoryStream())
                        {
                            stream.CopyTo(memStream);
                            memStream.Seek(0, SeekOrigin.Begin);

                            using (SKManagedStream skStream = new SKManagedStream(memStream))
                            {
                                webBitmap = SKBitmap.Decode(skStream);
                            }
                        }
                }
                catch
                {
                }

                Device.BeginInvokeOnMainThread(() => canvasView.InvalidateSurface());
            }, null);

            // Load resource bitmap
            string   resourceID = "SkiaSharpFormsDemos.Media.monkey.png";
            Assembly assembly   = GetType().GetTypeInfo().Assembly;

            using (Stream stream = assembly.GetManifestResourceStream(resourceID))
                using (SKManagedStream skStream = new SKManagedStream(stream))
                {
                    resourceBitmap = SKBitmap.Decode(skStream);
                }

            // Add tap gesture recognizer
            TapGestureRecognizer tapRecognizer = new TapGestureRecognizer();

            tapRecognizer.Tapped += async(sender, args) =>
            {
                // Load bitmap from photo library
                IPicturePicker picturePicker = DependencyService.Get <IPicturePicker>();

                using (Stream stream = await picturePicker.GetImageStreamAsync())
                {
                    if (stream != null)
                    {
                        using (MemoryStream memStream = new MemoryStream())
                        {
                            stream.CopyTo(memStream);
                            memStream.Seek(0, SeekOrigin.Begin);

                            using (SKManagedStream skStream = new SKManagedStream(memStream))
                            {
                                libraryBitmap = SKBitmap.Decode(skStream);
                            }
                        }
                        canvasView.InvalidateSurface();
                    }
                }
            };
            canvasView.GestureRecognizers.Add(tapRecognizer);
        }