byte array 'null' problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fidoZbady
    New Member
    • Apr 2010
    • 1

    byte array 'null' problem

    Hey,
    I am developing a software to view DICOM(medical) images, using the library ( http://sourceforge.net/projects/dicom-cs ). in C#
    I extract the pixel data as a byte array from the file and the try to view it using:

    Code:
    MemoryStream ms = new MemoryStream(byteArray);
    System.Drawing.Image img = Image.FromStream(ms);
    I get the ArgumentExcepti on Error: Parameter not valid.
    I learn that the method returns this error when it find null values.
    How can I convert those null values to zeros (0's)

    Here's the whole code in case anyone needs to try it:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    //using System.Web.UI.WebControls;
    using System.IO;
    using org.dicomcs.data;
    using org.dicomcs.dict;
    using org.dicomcs.util;
    using System.Drawing;
    
    namespace usinDcmsharp
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
                Stream ins = null;
                DcmParser parser = null;
                Dataset ds = null;
                FileInfo objFileinfo = new FileInfo(@"D:\Img0000001\Img0000001.dcm");
                ins = new BufferedStream(new FileStream(objFileinfo.FullName, FileMode.Open, FileAccess.Read));
                parser = new DcmParser(ins);
                FileFormat format = parser.DetectFileFormat();
                if (format != null)
                {
                    ds = new Dataset();
                    parser.DcmHandler = ds.DcmHandler;
                    parser.ParseDcmFile(format);
                    ByteBuffer byteBuffer = ds.GetByteBuffer(Tags.PixelData);
                    byte[] byteArray = (byte[])byteBuffer.ToArray();
    
                    MemoryStream ms = new MemoryStream(byteArray);
                   System.Drawing.Image img = Image.FromStream(ms);
                }
                else
                {
                    Response.Write("failed!");
                }
                ins.Close();
            }
        }
    }
    Thanks everyone,
    I will sincerely appreciate any help
Working...