protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); try { //Get the bitmap with the right rotation bitmap = BitmapHelpers.GetAndRotateBitmap(file.Path); //Resize the picture to be under 4MB //(Emotion API limitation and better for Android memory) bitmap = Bitmap.CreateScaledBitmap(bitmap, 2000, (int)(2000 * bitmap.Height / bitmap.Width), false); //Display the image imageView.SetImageBitmap(bitmap); //Loading message resultTextView.Text = GetString(Resource.String.loadText); pictureButton.Enabled = false; using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { //Get a stream bitmap.Compress(Bitmap.CompressFormat.Jpeg, 90, stream); stream.Seek(0, System.IO.SeekOrigin.Begin); //Get and display the happiness score var result = await Emotion_Core.GetAverageHappinessScore(stream); resultTextView.Text = Emotion_Core.GetHappinessMessage(result); resultMessage.Text = GetString(Resource.String.rateMessage); } } catch (Exception ex) { resultTextView.Text = ex.Message; } finally { pictureButton.Enabled = true; pictureButton.Text = GetString(Resource.String.imageSubmit); isCaptureMode = false; } }
protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); try { //Get the bitmap with the right rotation _bitmap = BitmapHelpers.GetAndRotateBitmap(_file.Path); //Resize the picture to be under 4MB (Emotion API limitation and better for Android memory) _bitmap = Bitmap.CreateScaledBitmap(_bitmap, 2000, (int)(2000 * _bitmap.Height / _bitmap.Width), false); //Display the image _imageView.SetImageBitmap(_bitmap); //Loading message _resultTextView.Text = "Loading..."; using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { //Get a stream _bitmap.Compress(Bitmap.CompressFormat.Jpeg, 90, stream); stream.Seek(0, System.IO.SeekOrigin.Begin); //Get and display the happiness score float result = await Core.GetAverageHappinessScore(stream); _resultTextView.Text = Core.GetHappinessMessage(result); } } catch (Exception ex) { _resultTextView.Text = ex.Message; } finally { _pictureButton.Text = "Reset"; _isCaptureMode = false; } }