I get invalid access to cross streams when I try to use BitMapImage in the cam_CaptureImageAvailable method, I tried to use the dispatcher, but this gave me the opportunity to not access the closed stream error, the exception System.ObjectDisposedException was unhandled.
void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
{
string fileName = folderName+"\\MyImage" + savedCounter + ".jpg";
try
{
Deployment.Current.Dispatcher.BeginInvoke(delegate()
{
txtDebug.Text = "Captured image available, saving picture ," + fileName;
});
Deployment.Current.Dispatcher.BeginInvoke(delegate()
{
});
e.ImageStream.Seek(0, SeekOrigin.Begin);
using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
}
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(e.ImageStream);
WriteableBitmap wb = new WriteableBitmap(bitmapImage);
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName))
{
wb.SaveJpeg(myFileStream, 10, 10, 0, 70);
}
}
}
finally
{
e.ImageStream.Close();
}
}
Tried it also
Deployment.Current.Dispatcher.BeginInvoke(delegate()
{
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(e.ImageStream);
WriteableBitmap wb = new WriteableBitmap(bitmapImage);
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName))
{
wb.SaveJpeg(myFileStream, 10, 10, 0, 70);
}
});
Someone can help me, I would really appreciate it.
source
share