本文整理汇总了C#中Android.Content.Intent.GetMediaFileExtraAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Intent.GetMediaFileExtraAsync方法的具体用法?C# Intent.GetMediaFileExtraAsync怎么用?C# Intent.GetMediaFileExtraAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Content.Intent
的用法示例。
在下文中一共展示了Intent.GetMediaFileExtraAsync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnActivityResult
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult (requestCode, resultCode, data);
if (resultCode == Result.Ok) {
data.GetMediaFileExtraAsync (this).ContinueWith (t =>
{
// save image in local database
System.Console.WriteLine("--> MediaFile: {0}", t.Result.Path);
// save image path to preferences so you can retrieve it
// in previous view
// ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
// ISharedPreferencesEditor editor = prefs.Edit();
// editor.PutString("image_path", t.Result.Path);
// editor.Apply();
}, TaskScheduler.FromCurrentSynchronizationContext());
}
// // make it available in the gallery
// Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
// if (_file != null) {
// Uri contentUri = Uri.FromFile (_file);
// mediaScanIntent.SetData (contentUri);
// SendBroadcast (mediaScanIntent);
// }
// this activity should be done after you save
// result from camera intent
Finish ();
}
示例2: OnActivityResult
public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Canceled) { Dismiss(); return; }
if (requestCode == 2)
{
data.GetMediaFileExtraAsync(Activity).ContinueWith(
t => OnBitmapLoaded(t.Result.Path),
TaskScheduler.FromCurrentSynchronizationContext());
}
}
示例3: OnActivityResult
protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Canceled || requestCode != SelectPhoto)
return;
MediaFile file = await data.GetMediaFileExtraAsync(this);
var email = SamplesExtensions.BuildSampleEmail()
.WithAttachment(file.Path)
.Build();
MessagingPlugin.EmailMessenger.SendSampleEmail(email);
}
示例4: OnActvitiResultCallback
public async void OnActvitiResultCallback(int requestCode, Result resultCode, Intent data)
{
// User canceled
if (resultCode == Result.Canceled)
return;
await data.GetMediaFileExtraAsync(Forms.Context).ContinueWith(t =>
{
if (OnImageData != null)
{
OnImageData(t.Result);
}
});
}
示例5: OnActivityResult
protected override void OnActivityResult(int requestCode,
Result resultCode, Intent data)
{
if (data != null) {
data.GetMediaFileExtraAsync(this)
.ContinueWith(t => {
if (ImageComplete != null)
ImageComplete((resultCode == Result.Ok) ? t.Result.Path : "");
}, TaskScheduler.FromCurrentSynchronizationContext())
.ContinueWith(tr => Console.WriteLine(tr.Exception.Message),
TaskContinuationOptions.NotOnRanToCompletion);
} else {
Console.WriteLine("No camera.");
}
// Return to parent activity (Forms)
this.Finish();
}
示例6: OnActivityResult
protected override async void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
Console.WriteLine ("requestCode: {0}", requestCode);
Console.WriteLine ("resultCode: {0}", resultCode);
// User canceled
if (resultCode == Result.Canceled)
return;
if (requestCode == 1) {
var fileTask = data.GetMediaFileExtraAsync (this);
await fileTask;
fileName = fileTask.Result.Path;
fileNameThumb = fileName.Replace(".jpg", "_thumb.jpg");
Console.WriteLine("Image path: {0}", fileName);
SetImage ();
// Cleanup any resources held by the MediaFile instance
fileTask.Result.Dispose();
//savet the file
var options = new BitmapFactory.Options {OutHeight = 128, OutWidth = 128};
var newBitmap = await BitmapFactory.DecodeFileAsync (fileName, options);
using (var @out = new System.IO.FileStream(fileNameThumb, System.IO.FileMode.Create)) {
newBitmap.Compress (Bitmap.CompressFormat.Jpeg, 90, @out);
}
newBitmap.Dispose ();
}
}
示例7: OnActivityResult
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
// User canceled
if (resultCode == Result.Canceled)
return;
data.GetMediaFileExtraAsync (this).ContinueWith (t => {
if (requestCode == 1) { // Video request
ShowVideo (t.Result.Path);
} else if (requestCode == 2) { // Image request
ShowImage (t.Result.Path);
}
}, TaskScheduler.FromCurrentSynchronizationContext());
}
示例8: HandlePhotoResultAsync
private async Task HandlePhotoResultAsync(Result resultCode, Intent data)
{
if (resultCode == Result.Ok)
{
MediaFile file = await data.GetMediaFileExtraAsync(this);
var bytes = Utilities.BinaryHandling.ReadFully(file.GetStream());
_mediaService.PhotoResult(bytes);
}
}
示例9: OnActivityResult
//photo
//ocr
protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
//PHOTO TAKER
if (requestCode == 1)
{
if (resultCode == Result.Canceled)
{
return;
}
MediaFile mediaFile = await data.GetMediaFileExtraAsync(Forms.Context);
System.Diagnostics.Debug.WriteLine(mediaFile.Path);
var imageInfo = ImageMeter.GetImageSize(mediaFile.Path);
MessagingCenter.Send<IPictureTaker, AccidentMediaViewModel>(this, "picTaken", imageInfo);
/* mediaFile = null;
GC.Collect();*/
}
//OCR PHOTO TAKER
if (requestCode == 2)
{
if (resultCode == Result.Canceled)
{
return;
}
MediaFile mediaFile = await data.GetMediaFileExtraAsync(Forms.Context);
System.Diagnostics.Debug.WriteLine(mediaFile.Path);
var imageInfo = ImageMeter.GetImageSize(mediaFile.Path);
MessagingCenter.Send<IPictureTaker, AccidentMediaViewModel>(this, "OCRPictureResult", imageInfo);
mediaFile = null;
GC.Collect();
}
//CHANGE LOCATION SETTINGS
if (requestCode == REQUEST_CHECK_SETTINGS)
{
switch (resultCode)
{
case Result.Ok:
Log.Info(TAG, "User agreed to make required location settings changes.");
//START LOCATION SERVICES
/*await StartLocationUpdates();*/
break;
case Result.Canceled:
Log.Info(TAG, "User chose not to make required location settings changes.");
break;
}
}
}
示例10: OnActivityResult
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
// base.OnActivityResult(requestCode, resultCode, data);
// if (resultCode == Result.Ok)
// {
// Stream stream = ContentResolver.OpenInputStream(data.Data);
// bitmap = BitmapFactory.DecodeStream(stream);
// selectedFoto.SetImageBitmap(bitmap);
// }
// User canceled
if (resultCode == Result.Canceled)
return;
data.GetMediaFileExtraAsync (this).ContinueWith (t => {
//Console.WriteLine (t.Result.Path);
DecodeBitmapAsync (t.Result.Path, 400, 400).ContinueWith (th => {
this.imgFoto.SetImageBitmap (this.bitmap = th.Result);
}, TaskScheduler.FromCurrentSynchronizationContext());
}, TaskScheduler.FromCurrentSynchronizationContext());
}
示例11: OnActivityResult
protected async override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
if (requestCode != 1)
return;
if (resultCode == Result.Canceled)
return;
var file = await data.GetMediaFileExtraAsync (this);
try
{
using (var stream = file.GetStream ()) {
var item = new Item ("I'm sharing great things using Xamarin!") {
Images = new[] { new ImageData (file.Path) }
};
Intent intent = Flickr.GetShareUI (this, item, shareResult => {
FindViewById<Button> (Resource.Id.Flickr).Text = "Flickr shared: " + shareResult;
});
StartActivity (intent);
}
}
catch (Exception ex)
{
ShowMessage("Facebook: " + ex.Message);
}
}
示例12: OnActivityResult
//Get Photo and Name from Contact
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
try
{
if (resultCode == Result.Canceled)
return;
if (requestCode == 2)
{
_player.FromContacts = false;
data.GetMediaFileExtraAsync(this).ContinueWith(t =>
PlayerImagePath = t.Result.Path);
}
if (requestCode == 3)
{
if (data == null || data.Data == null)
return;
var addressBook = new AddressBook(Application.Context)
{
PreferContactAggregation = false
};
var contact = addressBook.Load(data.Data.LastPathSegment);
if (string.IsNullOrEmpty(contact.DisplayName))
Toast.MakeText(this, Resources.GetString(Resource.String.NoNameString), ToastLength.Short)
.Show();
else
_editText.Text = contact.DisplayName;
if (contact.GetThumbnail() != null)
{
_player.FromContacts = true;
PlayerImagePath = data.Data.LastPathSegment;
}
else
{
_player.FromContacts = false;
PlayerImagePath = null;
}
}
}
catch (Exception exception)
{
GaService.TrackAppException(this.Class, "OnActivityResult", exception, false);
}
}
示例13: OnActivityResult
/* Snippet 2 Ende */
/// <summary>
/// Aufgenommenes Foto durch Project Oxford analysieren lassen und das Ergebnis visualisieren
/// </summary>
/// <param name="requestCode"></param>
/// <param name="resultCode"></param>
/// <param name="data"></param>
protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
var progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar1);
try
{
// User canceled
if (resultCode == Result.Canceled)
return;
MediaFile file = await data.GetMediaFileExtraAsync(this);
//Alte Face-Rectangles entfernen
var rellayout = FindViewById<RelativeLayout>(Resource.Id.relativeLayout1);
for (int i = 2; i < rellayout.ChildCount; i++)
{
rellayout.RemoveViewAt(i);
}
progressBar.Visibility = ViewStates.Visible;
//Foto in ImageView anzeigen
var bmp = BitmapFactory.DecodeFile(file.Path);
ImageView _imgView = FindViewById<ImageView>(Resource.Id.imageView1);
_imgView.SetImageBitmap(bmp);
//Bild Analyse durch Project Oxford
await _vm.Load(file.GetStream());
//Brechnen der Face Rectangle Positionen
float scale;
if (_imgView.Width / bmp.Width >= _imgView.Height / bmp.Height)
{
scale = (float)bmp.Height / _imgView.Height;
}
else
{
scale = (float)bmp.Width / _imgView.Width;
}
var relX = (_imgView.Width - bmp.Width / scale) / 2;
var relY = (_imgView.Height - bmp.Height / scale) / 2;
foreach (Emotion.Contract.Emotion emo in _vm.Emotions)
{
//Zeichnen der Face Rectangles
var butt = new Button(this);
GradientDrawable drawable = new GradientDrawable();
drawable.SetShape(ShapeType.Rectangle);
drawable.SetStroke(5, Color.Rgb(34, 135, 202));
drawable.SetColor(Color.Transparent);
butt.Background = drawable;
var layoutparams = new RelativeLayout.LayoutParams((int)Math.Ceiling(emo.FaceRectangle.Width / scale), (int)Math.Ceiling(emo.FaceRectangle.Height / scale));
layoutparams.SetMargins((int)Math.Ceiling(emo.FaceRectangle.Left / scale + relX), (int)Math.Ceiling(emo.FaceRectangle.Top / scale + relY), 0, 0);
butt.LayoutParameters = layoutparams;
butt.SetPadding(0, 0, 0, 0);
butt.Click += (e, s) =>
{
//Bei Klick auf Face Rectangle Emotionswerte anzeigen
(FindViewById<ProgressBar>(Resource.Id.angerProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Anger * 100);
(FindViewById<ProgressBar>(Resource.Id.contemptProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Contempt * 100);
(FindViewById<ProgressBar>(Resource.Id.disgustProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Disgust * 100);
(FindViewById<ProgressBar>(Resource.Id.fearProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Fear * 100);
(FindViewById<ProgressBar>(Resource.Id.happinessProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Happiness * 100);
(FindViewById<ProgressBar>(Resource.Id.neutralProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Neutral * 100);
(FindViewById<ProgressBar>(Resource.Id.sadnessProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Sadness * 100);
(FindViewById<ProgressBar>(Resource.Id.surpriseProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Surprise * 100);
};
rellayout.AddView(butt);
}
}
finally{ progressBar.Visibility = ViewStates.Invisible; }
}
示例14: OnActivityResult
protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Canceled)
return;
var mediaFile = await data.GetMediaFileExtraAsync(this);
var drawable = await BitmapDrawable.CreateFromStreamAsync(mediaFile.GetStream(), "temp.jpg");
var bitmap = ((BitmapDrawable)drawable).Bitmap;
var ratio = Math.Max(picture.Width / (float)bitmap.Width,
picture.Height / (float)bitmap.Height);
var width = (int)(bitmap.Width * ratio);
var height = (int)(bitmap.Height * ratio);
finalBitmap = await Task.Run(() =>
{
return Bitmap.CreateScaledBitmap(bitmap, width, height, true);
});
picture.SetImageBitmap(finalBitmap);
}