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); }
public void OnPictureTaken(byte[] data, Camera camera) { System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken here!"); GlobalSingletonHelpers.readExifOrientation(data); //var windowManager = Android.App.Application.Context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>(); //System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken device orientation:" + windowManager.DefaultDisplay.Rotation); System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken device orientation:" + orienter.currentOrientation); System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken camera orientation:" + degreesToRotateCameraToNatural); int rotateDegrees = degreesToRotateCameraToNatural + orienter.currentOrientation; // off the bottom. //GlobalStatusSingleton.latestImg = GlobalSingletonHelpers.rotateAndCrop(GlobalSingletonHelpers.SKBitmapFromBytes(data), rotateDegrees, offsetAmount); // off the top: //GlobalStatusSingleton.latestImg = GlobalSingletonHelpers.rotateAndCrop(GlobalSingletonHelpers.SKBitmapFromBytes(data), rotateDegrees, offsetAmount); // midpoint GlobalStatusSingleton.latestImg = GlobalSingletonHelpers.rotateAndCrop(GlobalSingletonHelpers.SKBitmapFromBytes(data), rotateDegrees); //GlobalStatusSingleton.mostRecentImgBytes = data; // this is the un modified data as jpg. bytes will give me a byte array (i think) //GlobalStatusSingleton.mostRecentImgBytes = GlobalStatusSingleton.latestImg.Bytes; this is 34mb.! :) SKImage outImg = SKImage.FromBitmap(GlobalStatusSingleton.latestImg); GlobalStatusSingleton.mostRecentImgBytes = outImg.Encode(SKEncodedImageFormat.Jpeg, 100).ToArray(); System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken here!"); timeToExit(this, null); }