OutOfMemoryException no dispositivo móvel
Estou desenvolvendo um aplicativo que usa um dispositivo móvel para tirar uma foto e enviá-la usando um serviço da web. Mas depois de tirar 4 fotos, recebo umaOutOfMemoryException
no código abaixo. Eu tentei ligar paraGC.Collect()
mas também não ajudou. Talvez alguém aqui possa me dar um conselho sobre como lidar com esse problem
public static Bitmap TakePicture()
{
var dialog = new CameraCaptureDialog
{
Resolution = new Size(1600, 1200),
StillQuality = CameraCaptureStillQuality.Default
};
dialog.ShowDialog();
// If the filename is empty the user took no picture
if (string.IsNullOrEmpty(dialog.FileName))
return null;
// (!) The OutOfMemoryException is thrown here (!)
var bitmap = new Bitmap(dialog.FileName);
File.Delete(dialog.FileName);
return bitmap;
}
A função é chamada por um manipulador de eventos:
private void _pictureBox_Click(object sender, EventArgs e)
{
_takePictureLinkLabel.Visible = false;
var image = Camera.TakePicture();
if (image == null)
return;
image = Camera.CutBitmap(image, 2.5);
_pictureBox.Image = image;
_image = Camera.ImageToByteArray(image);
}