I need to capture an image from my camera using xamarin.forms portable, and obtain access to the image byte[] data for image processing purposes.
How can this be done?
I have the working code that captures the image and simply shows it, using xlabs
public async Task<MediaFile> TakePicture()
{
Setup ();
ImageSource = null;
return await _Mediapicker.TakePhotoAsync (new CameraMediaStorageOptions {
DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400
}).ContinueWith (t => {
if (t.IsFaulted)
{
Status = t.Exception.InnerException.ToString();
}
else if (t.IsCanceled)
{
Status = "Canceled";
}
else
{
MediaFile mediaFile = t.Result;
ImageSource = ImageSource.FromStream(() => mediaFile.Source);
return mediaFile;
}
return null;
}, _scheduler);
}
and
private async void buttonTakePicture_Clicked() {
await cameraViewModel.TakePicture();
imageView.Source = cameraViewModel.ImageSource;
}
clicking the button launches cameraViewModel.TakePicture()
which in turn uses xlabs to actually take the picture on the device.
How can I alter the code to also give me the image raw data (or use a different code altogether)?
Thanks
You can take
mediaFile.Path
and pass it as a parameter for a DependencyService:To learn more about DependencyService you can access the documentation at: https://developer.xamarin.com/guides/xamarin-forms/dependency-service/