0
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(C:\Users\112\AppData\Local\Temp\113837.dcm))
{
    // obtain the XResolution and YResolution TIFFTAG values
    PropertyItem piXRes = bmp.GetPropertyItem(282);
    PropertyItem piYRes = bmp.GetPropertyItem(283);

    // values are stored as a 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;

    // now set the 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 the XResolution value
    Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

    Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
    Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

    bmp.SetPropertyItem(piXRes); // finally set the image property resolution
    bmp.SetPropertyItem(piYRes);

    bmp.SetResolution(600, 600); // now set the bitmap resolution

    bmp.Save(@"C:\output.tif"); // save the image
}

I'm getting an "Out of memory" error on the line using (Bitmap bmp = .... How can I solve that?

4

2 回答 2

2

With this line...

(Bitmap)Bitmap.FromFile(C:\Users\112\AppData\Local\Temp\113837.dcm)

...you are reading the whole raw data contained in a dicom file. That includes the Dicom Data Elements (fields containing information).

Extracting the image data is much more complicated than this. You should begin looking for some information about the Dicom format.

Other good sources of information to start can be found on Dabsoft and Medical Connections and, of course, on the David Clunie's website.

于 2013-05-03T08:26:29.557 回答
2

“内存不足”具有误导性。这确实意味着图像格式无法由.Net确定。

抱歉,.Net 不支持 DICOM 图像。有关支持的图像格式的信息,请参阅http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx

于 2013-05-03T05:44:16.567 回答