Compact Framework (Windows Mobile 6.1) を使用してPDA用のアプリケーションを開発しています。写真を撮り、画像を表示する必要があります。だから、私はCameraCaptureDialog
クラスを使用している写真を作るために:
using (var dialog = new CameraCaptureDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
{
}
}
GC.Collect();
GC.WaitForPendingFinalizers();
画像を表示するには、次を使用しますForm
。
public partial class FormImageViewer : Form
{
public FormImageViewer(string filename)
{
if (!File.Exists(filename))
throw new FileNotFoundException();
InitializeComponent();
// Here I have an OutOfMemoryException!
image = new Bitmap(fileName);
}
private Bitmap image;
private void menuItemOk_Click(object sender, EventArgs e)
{
if(image != null)
image.Dispose();
GC.Collect();
Close();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
double ratio = Math.Max((double)image.Width / Width, (double)image.Height / Height);
int x = (Width - (int)(image.Width / ratio)) / 2;
int y = (Height - (int)(image.Height / ratio)) / 2;
Rectangle destRect = new Rectangle(x, y, (int)(image.Width / ratio), (int)(image.Height / ratio));
Rectangle srcRect = new Rectangle(0, 0, image.Width, image.Height);
e.Graphics.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel);
}
}
問題は、最初にクラスOutOfMemoryException
を使用した場合にのみスローされることです。CameraCaptureDialog
写真を撮らなければ例外はありません。
なんで?この問題を解決するにはどうすればよいですか?