Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed an example of take a Picture with MonoDroid and MVVMCross
    primarykey
    data
    text
    <p>Can anyone point me to an example of <strong>take a Photo and store it using <code>MVVMCross</code></strong>?</p> <p>I have been searching but only have found this: <bR></p> <ul> <li><p><a href="https://stackoverflow.com/questions/8433648/monodroid-take-a-picture-with-camera">Monodroid Take a picture with Camera</a> (Doesn't Implement MVVMCross)</p></li> <li><p><a href="https://gist.github.com/3945799" rel="nofollow noreferrer">Video Recording</a> (It's Video and i can't make it work :S)</p></li> <li><p><a href="http://docs.xamarin.com/android/Recipes/Other_UX/Camera_Intent/Take_a_Picture_and_Save_Using_Camera_App" rel="nofollow noreferrer">The Oficialy Recipe Example</a> (It Works but does not implement MVVMCross)</p></li> </ul> <p>Thanks!!! </p> <blockquote> <p><strong>Resolved!</strong> Thanks! <br>To Future References: (Using Master Branch) <br><em>Credits to Stuart, I just changed the code to work with my reality</em></p> </blockquote> <pre><code>using Cirrious.MvvmCross.ExtensionMethods; using Cirrious.MvvmCross.Interfaces.Platform.Tasks; using Cirrious.MvvmCross.Interfaces.ServiceProvider; using SIGEP.DummyService; using SIGEP.Mobile.Core.Interfaces; namespace SIGEP.Mobile.Core.Models { public class PhotoService : IMvxServiceConsumer&lt;IMvxPictureChooserTask&gt; { private const int MaxPixelDimension = 1024; private const int DefaultJpegQuality = 92; public void GetNewPhoto() { this.GetService&lt;IMvxPictureChooserTask&gt;().TakePicture( MaxPixelDimension, DefaultJpegQuality, HandlePhotoAvailable, () =&gt; { /* cancel is ignored */ }); } public event EventHandler&lt;PhotoStreamEventArgs&gt; PhotoStreamAvailable; private void HandlePhotoAvailable(Stream pictureStream) { var handler = PhotoStreamAvailable; if (handler != null) { handler(this, new PhotoStreamEventArgs() { PictureStream = pictureStream, OnSucessGettingPhotoFileName = OnSucessGettingPhotoFileName }); } } public static void TakePhoto(Action&lt;string&gt; successFileName, Action&lt;Exception&gt; error) { var service = new PhotoService(); service.OnSucessGettingPhotoFileName = successFileName; service.OnError = error; service.GetNewPhoto(); service.PhotoStreamAvailable += new EventHandler&lt;PhotoStreamEventArgs&gt;(service_PhotoStreamAvailable); } static void service_PhotoStreamAvailable(object sender, PhotoStreamEventArgs e) { //grava pra ficheiro!!! var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var filename = Path.Combine(directory, "photo.jpeg"); string saveTo = filename; FileStream writeStream = new FileStream(saveTo, FileMode.Create, FileAccess.Write); ReadWriteStream(e.PictureStream, writeStream); e.OnSucessGettingPhotoFileName(filename); } private static void ReadWriteStream(Stream readStream, Stream writeStream) { int Length = 256; Byte[] buffer = new Byte[Length]; int bytesRead = readStream.Read(buffer, 0, Length); // write the required bytes while (bytesRead &gt; 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = readStream.Read(buffer, 0, Length); } readStream.Close(); writeStream.Close(); } public Action&lt;string&gt; OnSucessGettingPhotoFileName { get; set; } public Action&lt;Exception&gt; OnError { get; set; } } [Serializable] [ComVisible(true)] public class PhotoStreamEventArgs : EventArgs { public Stream PictureStream { get; set; } public Action&lt;string&gt; OnSucessGettingPhotoFileName { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload