i'm trying to read a bitmap file with the following code:
public void open(object o, EventArgs e)
{
fileOpenen.Filter = "Pictures (.BMP/.JPG/.GIF/.PNG)|*.bmp;*.jpg;*.gif;*.png";
if (fileOpenen.ShowDialog() == DialogResult.OK)
{
Bitmap open = new Bitmap(fileOpenen.FileName);
schets.bitmap = open;
this.nieuw(o, e);
}
It should load the bitmap into "schets", which consists of the following code:
class Schets
{
public Bitmap bitmap; // private naar public
public Schets()
{
bitmap = new Bitmap(1, 1);
}
public Graphics BitmapGraphics
{
get { return Graphics.FromImage(bitmap); }
}
public void VeranderAfmeting(Size sz)
{
if (sz.Width > bitmap.Size.Width || sz.Height > bitmap.Size.Height)
{
Bitmap nieuw = new Bitmap( Math.Max(sz.Width, bitmap.Size.Width)
, Math.Max(sz.Height, bitmap.Size.Height)
);
Graphics gr = Graphics.FromImage(nieuw);
gr.FillRectangle(Brushes.White, 0, 0, sz.Width, sz.Height);
gr.DrawImage(bitmap, 0, 0);
bitmap = nieuw;
}
}
public void Teken(Graphics gr)
{
gr.DrawImage(bitmap, 0, 0);
}
}
I can select a .bmp file from my hard drive but when i try to load it I get the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in Schets.exe