c# - Export Dicom images to tif format -
using (bitmap bmp = (bitmap)bitmap.fromfile(c:\users\112\appdata\local\temp\113837.dcm)) { // obtain xresolution , yresolution tifftag values propertyitem pixres = bmp.getpropertyitem(282); propertyitem piyres = bmp.getpropertyitem(283); // values stored rational number - numerator/denominator pair numerator = bitconverter.toint32(pixres.value, 0); denominator = bitconverter.toint32(pixres.value, 4); float xres = numerator / denominator; numerator = bitconverter.toint32(piyres.value, 0); denominator = bitconverter.toint32(piyres.value, 4); float yres = numerator / denominator; // set values byte[] numeratorbytes = new byte[4]; byte[] denominatorbytes = new byte[4]; numeratorbytes = bitconverter.getbytes(600); // specify resolution in numerator denominatorbytes = bitconverter.getbytes(1); array.copy(numeratorbytes, 0, pixres.value, 0, 4); // set xresolution value array.copy(denominatorbytes, 0, pixres.value, 4, 4); array.copy(numeratorbytes, 0, piyres.value, 0, 4); // set yresolution value array.copy(denominatorbytes, 0, piyres.value, 4, 4); bmp.setpropertyitem(pixres); // set image property resolution bmp.setpropertyitem(piyres); bmp.setresolution(600, 600); // set bitmap resolution bmp.save(@"c:\output.tif"); // save image }
i'm getting "out of memory" error on line using (bitmap bmp = ...
. how can solve that?
the "out of memory" misleading. means image format can not determined .net.
sorry .net not support dicom images. see http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx info on supported image formats.
Comments
Post a Comment