Reputation: 115
I'm working on Xamarin Android project and I want to implement taking photo with MvvmCross.
Here's my code:
public class PhotoService:IPhotoService
{
private const int MaxPixelDimension = 1280;
private const int DefaultJpegQuality = 90;
private Stream imageStream;
public Stream ImageStream
{
get { return imageStream; }
set { imageStream = value; }
}
public void GetPhoto()
{
var task = Mvx.Resolve<IMvxPictureChooserTask>();
task.TakePicture(
MaxPixelDimension,
DefaultJpegQuality,
SavePicture, null);
}
private void SavePicture(Stream stream)
{
ImageStream = stream;
}
}
but in:
task.TakePicture(
MaxPixelDimension,
DefaultJpegQuality,
SavePicture,
null);
I have error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
UPDATE
in call stack I have:
0x0 in Android.Content.Intent..ctor at /Users/builder/data/lanes/3511/501e63ce/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Content.Intent.cs:1275,6 C# 0x12 in MvvmCross.Plugins.PictureChooser.Droid.MvxPictureChooserTask.TakePicture C#
0x3A in App.Services.PhotoService.PhotoService.GetPhoto at C:\app\App.Services\PhotoService\PhotoService.cs:38,4 C#
0x7 in App.ViewModels.ViewModels.MainViewModel.TakePhoto at C:\app\App.ViewModels\ViewModels\MainViewModel.cs:49,4 C#
Upvotes: 0
Views: 671
Reputation: 607
Alternative solution you can use Media Plugin that available in nuget
https://www.nuget.org/packages/Xam.Plugin.Media/
You can use dependency service to call the takePictureAsync
method from android project. With this library you can specify file name and folder path to store your image. This library can also take video using takeVideoAsync
method.
Upvotes: 1
Reputation: 767
I believe you need to add the MVVMCross.Pugin.PictureChooser package to your Core and platform specific projects.
Upvotes: 0