public FileSystemImage(int width, int height, string saveToBmp)
        {
            filePath   = saveToBmp;
            fileStream = File.Open(saveToBmp, FileMode.Create, FileAccess.Write, FileShare.None);
            using (var bw = new System.IO.BinaryWriter(fileStream, Encoding.UTF8, true))
            {
                var bheader = new DcmBITMAPFILEHEADER();
                bheader.bfOffBits   = 54;
                bheader.bfReserved1 = 0;
                bheader.bfReserved2 = 0;
                bheader.bfSize      = (uint)(54 + width * height * 4);
                bheader.bfType      = 19778;

                var binfo = new DcmBITMAPINFOHEADER();
                binfo.biBitCount     = 32;
                binfo.biClrImportant = 0;
                binfo.biClrUsed      = 0;
                binfo.biCompression  = DcmBitmapCompressionMode.BI_RGB;

                binfo.biWidth         = width;
                binfo.biHeight        = height;
                binfo.biPlanes        = 1;
                binfo.biSize          = 40;
                binfo.biSizeImage     = 0;
                binfo.biXPelsPerMeter = 3978;
                binfo.biYPelsPerMeter = 3978;
                var hd = DcmStructToBytes(bheader);
                var bd = DcmStructToBytes(binfo);
                bw.Write(hd);
                bw.Write(bd);
            }
        }
示例#2
0
        public override bool Render(int components, bool bRorate90, string saveToPath)
        {
            //  var format = components == 4 ? PixelFormat.Format32bppArgb : PixelFormat.Format32bppRgb;
            var _pixels = this.pixels;

            using (var fs = new System.IO.FileStream(saveToPath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                using (var bw = new System.IO.BinaryWriter(fs))
                {
                    var bheader = new DcmBITMAPFILEHEADER();
                    bheader.bfOffBits   = 54;
                    bheader.bfReserved1 = 0;
                    bheader.bfReserved2 = 0;
                    bheader.bfSize      = (uint)(54 + _pixels.ByteSize);
                    bheader.bfType      = 19778;

                    var binfo = new DcmBITMAPINFOHEADER();
                    binfo.biBitCount     = 32;
                    binfo.biClrImportant = 0;
                    binfo.biClrUsed      = 0;
                    binfo.biCompression  = DcmBitmapCompressionMode.BI_RGB;
                    if (bRorate90)
                    {
                        //----旋转90度, 其它参数不变
                        binfo.biHeight = this.width;
                        binfo.biWidth  = this.height;
                    }
                    else
                    {
                        binfo.biWidth  = this.width;
                        binfo.biHeight = this.height;
                    }

                    binfo.biPlanes        = 1;
                    binfo.biSize          = 40;
                    binfo.biSizeImage     = 0;
                    binfo.biXPelsPerMeter = 3978;
                    binfo.biYPelsPerMeter = 3978;
                    var hd = DcmStructToBytes(bheader);
                    var bd = DcmStructToBytes(binfo);

                    bw.Write(hd);
                    bw.Write(bd);

                    if (false == bRorate90)
                    {
                        for (int i = this.height; i > 0; i--)
                        {
                            //int[] rawData = new int[ScaledData.Width];
                            //Buffer.BlockCopy(_pixels.Data, (i - 1) * ScaledData.Width, rawData, 0, ScaledData.Width);
                            for (int j = 0; j < this.width; j++)
                            {
                                int    ax = _pixels[(i - 1) * this.width + j];
                                byte[] ar = BitConverter.GetBytes(ax);
                                bw.Write(ar);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < this.width; i++)
                        {
                            for (int j = 0; j < this.height; j++)
                            {
                                int    aw = _pixels[j * this.width + i];
                                byte[] ar = BitConverter.GetBytes(aw);
                                bw.Write(ar);
                            }
                        }
                    }
                    bw.Flush();
                    bw.Close();
                    fs.Close();
                    return(true);
                }
        }
示例#3
0
        public override bool Render(int components, System.IO.MemoryStream bw, out int w, out int h, bool bRorate90)
        {
            w = this.width;
            h = this.height;
            var _pixels = this.pixels;
            {
                var bheader = new DcmBITMAPFILEHEADER();
                bheader.bfOffBits   = 54;
                bheader.bfReserved1 = 0;
                bheader.bfReserved2 = 0;
                bheader.bfSize      = (uint)(54 + _pixels.ByteSize);
                bheader.bfType      = 19778;

                var binfo = new DcmBITMAPINFOHEADER();
                binfo.biBitCount     = 32;
                binfo.biClrImportant = 0;
                binfo.biClrUsed      = 0;
                binfo.biCompression  = DcmBitmapCompressionMode.BI_RGB;
                if (bRorate90)
                {
                    //----旋转90度, 其它参数不变
                    h = this.width;
                    w = this.height;
                }
                else
                {
                    w = this.width;
                    h = this.height;
                }

                binfo.biPlanes        = 1;
                binfo.biSize          = 40;
                binfo.biSizeImage     = 0;
                binfo.biXPelsPerMeter = 3978;
                binfo.biYPelsPerMeter = 3978;
                var hd = DcmStructToBytes(bheader);
                var bd = DcmStructToBytes(binfo);

                bw.Write(hd, 0, hd.Length);
                bw.Write(bd, 0, bd.Length);



                if (false == bRorate90)
                {
                    for (int i = this.height; i > 0; i--)
                    {
                        //int[] rawData = new int[ScaledData.Width];
                        //Buffer.BlockCopy(_pixels.Data, (i - 1) * ScaledData.Width, rawData, 0, ScaledData.Width);
                        for (int j = 0; j < this.width; j++)
                        {
                            int    ax = _pixels[(i - 1) * this.width + j];
                            byte[] ar = BitConverter.GetBytes(ax);
                            bw.Write(ar, 0, 3);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < this.width; i++)
                    {
                        for (int j = 0; j < this.height; j++)
                        {
                            int    aw = _pixels[j * this.width + i];
                            byte[] ar = BitConverter.GetBytes(aw);
                            bw.Write(ar, 0, 3);
                        }
                    }
                }
                bw.Flush();

                return(true);
            }
        }