c# converting list of BMP to array of DICOM files -
i can convert bitmap dicom using following:
bitmap bmp = new bitmap(system.drawing.image.fromfile(system.web.httpcontext.current.server.mappath("~/filename))); color c = bmp.getpixel(0, 0); bmp.maketransparent(c); im.import(bmp);
it works great.
now trying convert list of bitmap images list of dicom using:
mysession.current.dicomarray = new dicomimage[nfiles]; mysession.current.bmparray = new bitmap[nfiles]; ..... (int = 0; < nfiles; ++i) { mysession.current.bmparray[i] = new bitmap(system.drawing.image.fromfile( system.web.httpcontext.current.server.mappath( "~/" + imagepath + files[i]))); } ...... (int = 0; < nfiles; ++i) { mysession.current.dicomarray[i].import(mysession.current.bmparray[i]); }
i following error:
object reference not set instance of object.
i can see files in bmparray. guess using statement wrong. appreciate suggestions.
as pointed out @adilmammadov in comments above, problem due fact have not yet defined individual members of dicomarray
array, when calling import
method in second loop, invoking on null
object.
if dicomimage
has public constructor (it not clear question if does), either add line adil suggests:
mysession.current.dicomarray[i] = new dicomimage();
before import
line in second loop.
alternatively, use linq method enumerable.repeat create array:
mysession.current.dicomarray = enumerable.repeat(new dicomimage(), nfiles).toarray();
Comments
Post a Comment