Tuesday 15 January 2013

Cannot read Bitmap file using C# -



Cannot read Bitmap file using C# -

this question has reply here:

what nullreferenceexception , how prepare it? 21 answers

i'm trying read bitmap file next 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 bitmap "schets", consists of next code:

class schets { public bitmap bitmap; // private naar public public schets() { bitmap = new bitmap(1, 1); } public graphics bitmapgraphics { { homecoming 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 .bmp file hard drive when seek load next error: an unhandled exception of type 'system.nullreferenceexception' occurred in schets.exe

from strack trace can see 'system.nullreferenceexception' ocucure. point line seek access not yet initialized object. initialize object , work.

c# bitmap

No comments:

Post a Comment