I am using the following function in my app to capture a photo using MediaCapture class and copy it to clipboard:
async private void UseCamera()
{
var _ImageFormat = ImageEncodingProperties.CreatePng();
var _fileStream = new InMemoryRandomAccessStream();
try
{
await _mediaCapture.InitializeAsync();
}
catch (Exception e)
{
new Windows.UI.Popups.MessageDialog(e.Message).ShowAsync();
}
try
{
await _mediaCapture.CapturePhotoToStreamAsync(_ImageFormat, _fileStream);
}
catch (Exception e)
{
new Windows.UI.Popups.MessageDialog(e.Message).ShowAsync();
}
var _streamRef = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromStream(_fileStream);
_dataPackage.SetBitmap(_streamRef);
Clipboard.SetContent(_dataPackage);
Clipboard.Flush();
}
The app is running fine on my local machine. But when I try to run it on simulator, i am given this error:
"An exception of type 'System.UnauthorizedAccessException' occurred in SensorGridCamera.exe but was not handled in user code
Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
Can anyone help me with it?
MessageDialog
in code temporary and see the result because some time it throwsUnauthorizedAccessException
. Don't useasync void
in method, useasync Task
– Farhan Ghumra