1
我想製作一個應用程序,它可以使用相機拍攝圖像並將其存儲在手機的獨立存儲器中。如何在每次運行中存儲7張圖像(即每次模擬器被激活),對於我捕獲和保存的八張圖像,我得到一個內存不足的異常。如果我必須在隔離存儲中存儲更多圖像,我必須停止調試並重新啓動調試。我是wp7開發新手。我是使用debugging.Please模擬器幫助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");
}
}
}
可以請你修改我上面的代碼? – user1155478 2012-01-18 07:03:10
類文檔有兩個成員,即名稱和照片,都是字符串。而且照片只有圖像文件的字符串路徑 – user1155478 2012-01-18 07:23:25
我試圖包含一個例子abobe。它使答案相當長;對於那個很抱歉! – faester 2012-01-23 11:16:33