B
Bruce
I am making a simple application that displays a single bitmap image in
a picturebox. I am using the Windows Mobile SDK and my application
works fine on the emulator, but on the phone I am getting an OutOfMemory
Exception whenever I call new Bitmap(filepath). This happens the first time
an image is loaded and I have tried forcing Garbage Collection before I load
it. I am using a Treo 700w Windows Mobile Smartphone. Below is the code I
am trying to run.
There is no other application running at the same time, so it is amazing
that I'm getting an OutOfMemory exception. Am I doing something wrong, or
is there any way to prevent this exception?
-- Bruce
private void menuItem3_Click(object sender, EventArgs e)
{
bool loadImage = false;
using (SelectPictureDialog picturePicker = new SelectPictureDialog())
{
picturePicker.Owner = this;
picturePicker.InitialDirectory = @"\Images";
picturePicker.CameraAccess = false;
picturePicker.ShowDrmContent = true;
picturePicker.ShowForwardLockedContent = false;
picturePicker.Filter = "All files|*.*";
DialogResult result = picturePicker.ShowDialog();
if (result == DialogResult.OK)
{
string fileExtension = Path.GetExtension(picturePicker.FileName);
assetName = picturePicker.FileName;
if (fileExtension.ToLower() == ".jpg")
loadImage = true;
}
}
this.Refresh();
if (loadImage)
{
try
{
pictureBox1.Image = new Bitmap(assetName);
}
catch
{
GC.Collect();
pictureBox1.Image = new Bitmap(assetName);
}
}
}
a picturebox. I am using the Windows Mobile SDK and my application
works fine on the emulator, but on the phone I am getting an OutOfMemory
Exception whenever I call new Bitmap(filepath). This happens the first time
an image is loaded and I have tried forcing Garbage Collection before I load
it. I am using a Treo 700w Windows Mobile Smartphone. Below is the code I
am trying to run.
There is no other application running at the same time, so it is amazing
that I'm getting an OutOfMemory exception. Am I doing something wrong, or
is there any way to prevent this exception?
-- Bruce
private void menuItem3_Click(object sender, EventArgs e)
{
bool loadImage = false;
using (SelectPictureDialog picturePicker = new SelectPictureDialog())
{
picturePicker.Owner = this;
picturePicker.InitialDirectory = @"\Images";
picturePicker.CameraAccess = false;
picturePicker.ShowDrmContent = true;
picturePicker.ShowForwardLockedContent = false;
picturePicker.Filter = "All files|*.*";
DialogResult result = picturePicker.ShowDialog();
if (result == DialogResult.OK)
{
string fileExtension = Path.GetExtension(picturePicker.FileName);
assetName = picturePicker.FileName;
if (fileExtension.ToLower() == ".jpg")
loadImage = true;
}
}
this.Refresh();
if (loadImage)
{
try
{
pictureBox1.Image = new Bitmap(assetName);
}
catch
{
GC.Collect();
pictureBox1.Image = new Bitmap(assetName);
}
}
}