我想制作一个使用相机捕获图像并将其存储在手机的隔离存储中的应用程序。但是,我能够在每次运行中存储 7 个图像(即每次激活模拟器时)和 8 个图像我捕获并保存,我得到一个内存不足的异常。如果我必须在隔离存储中存储更多图像,我必须停止调试并重新启动调试。我是 wp7 开发的新手。我正在使用模拟器进行调试。请帮忙
Stream doc_photo;
List<document> doc_list = new List<document>();
document newDoc = new document();
public Page2()
{
InitializeComponent();
}
private void captureDocumentImage(object sender, RoutedEventArgs e)
{
ShowCameraCaptureTask();
}
private void ShowCameraCaptureTask()
{
CameraCaptureTask photoCameraCapture = new CameraCaptureTask();
photoCameraCapture = new CameraCaptureTask();
photoCameraCapture.Completed += new EventHandler<PhotoResult>photoCameraCapture_Completed);
photoCameraCapture.Show();
}
void photoCameraCapture_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
capturedImage.Source = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
doc_photo = e.ChosenPhoto;
}
}
private void SaveToIsolatedStorage(Stream imageStream, string fileName)
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(fileName))
{
myIsolatedStorage.DeleteFile(fileName);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(fileName);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(imageStream);
try
{
WriteableBitmap wb = new WriteableBitmap(bitmap);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
catch (OutOfMemoryException e1)
{
MessageBox.Show("memory exceeded");
}
}
}
private void save_buttonclicked(object sender, RoutedEventArgs e)
{
if (namebox.Text != "" && doc_photo!=null)
{
newDoc.doc_name = namebox.Text;
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
if(!myIsolatedStorage.DirectoryExists(App.current_panorama_page))
{
myIsolatedStorage.CreateDirectory(App.current_panorama_page);
}
newDoc.photo = App.current_panorama_page + "/" + namebox.Text + ".jpg";//
SaveToIsolatedStorage(doc_photo, newDoc.photo);
doc_list.Add(newDoc);
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
if (namebox.Text == "")
{
MessageBox.Show("Enter the name");
}
else if (doc_photo == null)
{
MessageBox.Show("Capture an Image");
}
}
}