Exemple #1
0
        public void OnCameraFinished(Object sender, EventArgs e)
        {
            /*
             * var filepath = Path.Combine(Environment.GetFolderPath(
             *                 Environment.SpecialFolder.MyDocuments), "tmp.png");
             */

            InvokeOnMainThread(() => {
                Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon");
                if (CameraServices_iOS.exitFromPhoto == true)    // probably better to acheive this by subclassing the event. but i need something quick and dirty.
                {
                    string nextFileName = GlobalStatusSingleton.IMAGE_NAME_PREFIX + GlobalStatusSingleton.imgsTakenTracker + ".jpg";
                    var filepath        = Path.Combine(Environment.GetFolderPath(
                                                           Environment.SpecialFolder.MyDocuments), nextFileName);

                    SKBitmap bitmap = GlobalSingletonHelpers.SKBitmapFromBytes(GlobalStatusSingleton.mostRecentImgBytes);
                    if (bitmap != null)
                    {
                        int degreesToRotate = CameraServices_iOS.calculateRotationDegrees();
                        Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon time to rotate and crop; degrees:" + degreesToRotate);
                        SKBitmap finalBmp = GlobalSingletonHelpers.rotateAndCrop(bitmap, degreesToRotate);
                        //((MainPage)((Xamarin.Forms.Application.Current as App).MainPage)).img.Bitmap = finalBmp;
                        NSData finalBytes                        = NSData.FromArray(finalBmp.Bytes);
                        AppDelegate.snappedImgData               = finalBytes;
                        GlobalStatusSingleton.latestImg          = finalBmp;
                        GlobalStatusSingleton.mostRecentImgBytes = finalBmp.Bytes; // this fails... need to encode as a jpeg first.

                        SKImage img = SKImage.FromBitmap(finalBmp);
                        GlobalStatusSingleton.mostRecentImgBytes = img.Encode(SKEncodedImageFormat.Jpeg, 100).ToArray();
                        SKBitmap test = GlobalSingletonHelpers.SKBitmapFromBytes(GlobalStatusSingleton.mostRecentImgBytes);
                        //SKBitmap test = GlobalSingletonHelpers.SKBitmapFromBytes(GlobalStatusSingleton.mostRecentImgBytes);

                        Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon finalBMP sq?");
                    }
                    else
                    {
                        Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon bitmap was null");
                    }

                    if (snappedImgData != null)
                    {
                        snappedImgData.Save(filepath, false);
                    }

                    byte[] imgBytes = null;
                    using (var streamReader = new System.IO.StreamReader(filepath)) {
                        using (System.IO.MemoryStream memStream = new System.IO.MemoryStream()) {
                            streamReader.BaseStream.CopyTo(memStream);
                            imgBytes = memStream.ToArray();
                        }
                    }

                    ((ICamera)(((IExposeCamera)(Xamarin.Forms.Application.Current as App).MainPage).getCamera())).ShowImage(filepath, imgBytes);
                    GlobalStatusSingleton.imgsTakenTracker++;
                }
            });
            uiApplication.KeyWindow.RootViewController.DismissViewController(true, null);
        }
Exemple #2
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        // @todo Check for camera availability and set in GlobalStatusSingleton
        public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
        {
            this.uiApplication = uiApplication;
            Forms.Init();
            CarouselViewRenderer.Init();
            //var cv = typeof(Xamarin.Forms.CarouselView);
            //var assembly = Assembly.Load(cv.FullName);

            Debug.WriteLine("DHB:AppDelegate:FinishedLaunching pre imgPath.");
            GlobalStatusSingleton.imgPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            Debug.WriteLine("DHB:AppDelegate:FinishedLaunching imgPath=" + GlobalStatusSingleton.imgPath);

            LoadApplication(new App());

            if ((!Xamarin.Forms.Application.Current.Properties.ContainsKey(App.PROPERTY_UUID)) ||
                (Xamarin.Forms.Application.Current.Properties[App.PROPERTY_UUID].Equals("")))
            {
                NSUuid generator = new NSUuid();
                generator.Init();
                GlobalStatusSingleton.UUID = generator.ToString();
                // this gives the device id.
                //UIKit.UIDevice.CurrentDevice.IdentifierForVendor.AsString();
            }
            Debug.WriteLine("DHB:AppDelegate:FinishedLaunching guid set to:" + GlobalStatusSingleton.UUID);

            //notificationTest();
            notify.RequestAuthorization();

            fbLogin.Init();
            FacebookLogin_iOS.uiApplication = uiApplication;
            CameraServices_iOS myCamera = new CameraServices_iOS();

            ((ICamera)(((IExposeCamera)(Xamarin.Forms.Application.Current as App).MainPage).getCamera())).ShouldTakePicture += () => {
                Debug.WriteLine("pre launch");
                uiApplication.KeyWindow.RootViewController.PresentViewController(myCamera, true, null);
                Debug.WriteLine("present called already");
            };

            //< FinishedPickingMedia
            myCamera.FinishedPickingMedia += OnCameraFinished;

            //> FinishedPickingMedia

            //< Canceled
            // i don't have a cancel button...
            //imagePicker.Canceled += (sender, e) => uiApplication.KeyWindow.RootViewController.DismissViewController(true, null);
            //> Canceled

            return(base.FinishedLaunching(uiApplication, launchOptions));
        }