public async Task SendPhoto(byte[] imageBytes) { Photo photo = new Photo { InMemory = imageBytes, CreatedAt = DateTime.Now, UserCondition = App.SelectedCondition }; var navigationPage = new PhotoEditPage(photo); await App.Current.MainPage.Navigation.PopAsync(); await App.Current.MainPage.Navigation.PushAsync(navigationPage); }
public async void OnPictureTaken(byte[] data, Android.Hardware.Camera camera) { Bitmap bitmapImage = BitmapFactory.DecodeByteArray(data, 0, data.Length); // compare to a decent sized photo float scale = (bitmapImage.Height * bitmapImage.Width) / 1228800; // If the image is significantly bigger than this, scale it down! if (scale > 1.2f) { int newWidth = (int)(bitmapImage.Width / (scale / 2)); int newHeight = (int)(bitmapImage.Height / (scale / 2)); bitmapImage = Bitmap.CreateScaledBitmap(bitmapImage, newWidth, newHeight, false); } if (cameraType == CameraFacing.Back) { bitmapImage = rotateImage(bitmapImage, 90); } else { bitmapImage = rotateImage(bitmapImage, -90); } using (var imageStream = new MemoryStream()) { await bitmapImage.CompressAsync(Bitmap.CompressFormat.Jpeg, 60, imageStream); bitmapImage.Recycle(); imageBytes = imageStream.ToArray(); } Photo photo = new Photo { InMemory = imageBytes, CreatedAt = DateTime.Now, UserCondition = App.SelectedCondition }; var navigationPage = new PhotoEditPage(photo); UserDialogs.Instance.HideLoading(); //camera.Release(); await App.Current.MainPage.Navigation.PopAsync(); await App.Current.MainPage.Navigation.PushAsync(navigationPage); }
public async void OnPictureTaken(byte[] data) { try { Bitmap bitmapImage = BitmapFactory.DecodeByteArray(data, 0, data.Length); data = null; if (!backCam) { Matrix matrix = new Matrix(); matrix.PreScale(-1.0f, 1.0f); bitmapImage = Bitmap.CreateBitmap(bitmapImage, 0, 0, bitmapImage.Width, bitmapImage.Width, matrix, false); } using (var imageStream = new MemoryStream()) { await bitmapImage.CompressAsync(Bitmap.CompressFormat.Jpeg, 80, imageStream); bitmapImage.Recycle(); imageBytes = imageStream.ToArray(); } Photo photo = new Photo { InMemory = imageBytes, CreatedAt = DateTime.Now, UserCondition = App.SelectedCondition }; var navigationPage = new PhotoEditPage(photo); Activity.RunOnUiThread(() => { App.Current.MainPage.Navigation.PopAsync(); App.Current.MainPage.Navigation.PushAsync(navigationPage); }); } catch (System.Exception e) { System.Console.WriteLine(e); } }