【发布时间】:2010-10-10 06:52:38
【问题描述】:
我正在开发一个应用程序,它使用移动设备拍摄照片并使用网络服务发送。但是在我拍了 4 张照片之后,我在下面的代码中得到了一个 OutOfMemoryException。我试过打电话给GC.Collect(),但也没有用。也许这里有人可以给我一个建议如何处理这个问题。
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;
}
函数由事件处理程序调用:
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);
}
【问题讨论】:
标签: .net .net-3.5 memory windows-mobile out-of-memory