当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.MemoryStream.Dispose方法代码示例

本文整理汇总了C#中System.IO.MemoryStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.Dispose方法的具体用法?C# System.IO.MemoryStream.Dispose怎么用?C# System.IO.MemoryStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.MemoryStream的用法示例。


在下文中一共展示了System.IO.MemoryStream.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnZipCompress

        public static string UnZipCompress(this string value)
        {
            //Transform string into byte[]
            byte[] byteArray = new byte[value.Length];
            int indexBA = 0;
            foreach (char item in value.ToCharArray())
            {
                byteArray[indexBA++] = (byte)item;
            }

            //Prepare for decompress
            System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray);
            System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms,
                System.IO.Compression.CompressionMode.Decompress);

            //Reset variable to collect uncompressed result
            byteArray = new byte[byteArray.Length];

            //Decompress
            int rByte = sr.Read(byteArray, 0, byteArray.Length);

            //Transform byte[] unzip data to string
            System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte);
            //Read the number of bytes GZipStream red and do not a for each bytes in
            //resultByteArray;
            for (int i = 0; i < rByte; i++)
            {
                sB.Append((char)byteArray[i]);
            }
            sr.Close();
            ms.Close();
            sr.Dispose();
            ms.Dispose();
            return sB.ToString();
        }
开发者ID:Cyberbanan,项目名称:voxeliq,代码行数:35,代码来源:StringExtensions.cs

示例2: ZipCompress

        public static string ZipCompress(this string value)
        {
            //Transform string into byte[]  
            byte[] byteArray = new byte[value.Length];
            int indexBA = 0;
            foreach (char item in value.ToCharArray())
            {
                byteArray[indexBA++] = (byte)item;
            }

            //Prepare for compress
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms,
                System.IO.Compression.CompressionMode.Compress);

            //Compress
            sw.Write(byteArray, 0, byteArray.Length);
            //Close, DO NOT FLUSH cause bytes will go missing...
            sw.Close();

            //Transform byte[] zip data to string
            byteArray = ms.ToArray();
            System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
            foreach (byte item in byteArray)
            {
                sB.Append((char)item);
            }
            ms.Close();
            sw.Dispose();
            ms.Dispose();
            return sB.ToString();
        }
开发者ID:Cyberbanan,项目名称:voxeliq,代码行数:32,代码来源:StringExtensions.cs

示例3: GetImageMime

        public static string GetImageMime(byte[] bt64)
        {
            string strImageMime = "image/unknown";

            try
            {
                System.IO.MemoryStream msInputStream = new System.IO.MemoryStream(bt64);
                System.Drawing.Image imgThisImage = System.Drawing.Image.FromStream(msInputStream);

                foreach (System.Drawing.Imaging.ImageCodecInfo cdcInfo in System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders())
                {
                    if (cdcInfo.FormatID == imgThisImage.RawFormat.Guid)
                    {
                        strImageMime = cdcInfo.MimeType;
                        break;
                    }
                }

                imgThisImage.Dispose();
                imgThisImage = null;
                msInputStream.Dispose();
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            return strImageMime;
        }
开发者ID:aarya289,项目名称:DnDFileUpload,代码行数:29,代码来源:IndexPageDebug.aspx.cs

示例4: FromSerializedString

 public static PlayerList FromSerializedString(string s)
 {
     PlayerList p = null;
     XmlSerializer x = new XmlSerializer(typeof(PlayerList));
     System.IO.MemoryStream ms = new System.IO.MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(s));
     p = (PlayerList)x.Deserialize(ms);
     ms.Dispose();
     return p;
 }
开发者ID:mbaldini,项目名称:F10GenTool,代码行数:9,代码来源:PlayerList.cs

示例5: GetSerializedString

 public string GetSerializedString()
 {
     XmlSerializer x = new XmlSerializer(this.GetType());
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     x.Serialize((System.IO.Stream)ms, this);
     var buffer = ms.ToArray();
     ms.Close();
     ms.Dispose();
     string s = System.Text.ASCIIEncoding.ASCII.GetString(buffer);
     return s;
 }
开发者ID:mbaldini,项目名称:F10GenTool,代码行数:11,代码来源:PlayerList.cs

示例6: TestModifySubjectLine

        public void TestModifySubjectLine()
        {
            System.IO.Stream inputStream = null;
            System.IO.Stream outputStream = null;

            try
            {
                string testemail = @"P:\Projects\Hygiene\src\TestDocuments\TagActionTestMail.eml";
                byte[] inputBytes = System.IO.File.ReadAllBytes(testemail);
                inputStream = new System.IO.MemoryStream(inputBytes);

                MimeHelper mimeHelper = new MimeHelper(inputStream);

                Guid guid = Guid.NewGuid();
                mimeHelper.PrefixSubjectLine(guid.ToString());

                outputStream = mimeHelper.MimeStream;

                byte[] buffer = new byte[outputStream.Length];
                outputStream.Position = 0;
                int numBytesToRead = (int)outputStream.Length;
                int numBytesRead = 0;
                while (numBytesToRead > 0)
                {
                    int n = outputStream.Read(buffer, numBytesRead, numBytesToRead);

                    // The end of the file is reached.
                    if (n == 0)
                        break;

                    numBytesRead += n;
                    numBytesToRead -= n;
                }
                outputStream.Position = 0;

                string email = System.Text.Encoding.Unicode.GetString(buffer);
                string subjecttofind = "subject: " + guid.ToString() + "Test for PES";
                Assert.Greater(email.IndexOf(subjecttofind), 0);
            }
            catch (System.Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (inputStream != null)
                    inputStream.Dispose();

                if (outputStream != null)
                    outputStream.Dispose();
            }
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:52,代码来源:TestMimeHelper.cs

示例7: GZip

 public static byte[] GZip(this byte[] bytes)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     GZipStream gs = new GZipStream(ms, CompressionMode.Compress, true);
     gs.Write(bytes, 0, bytes.Length);
     gs.Close();
     gs.Dispose();
     ms.Position = 0;
     bytes = new byte[ms.Length];
     ms.Read(bytes, 0, (int)ms.Length);
     ms.Close();
     ms.Dispose();
     return bytes;
 }
开发者ID:EricKilla,项目名称:mcforge,代码行数:14,代码来源:Extensions.cs

示例8: GetBackgroundPic

        public static Bitmap GetBackgroundPic(I_DLE device, int address, byte mode, byte g_code_id, ref string desc)
        {
            RGS_SetBackgroundPic_frame frame=null;
            System.IO.MemoryStream ms;
            byte[] cmdText = new byte[] { 0x98, mode, g_code_id };
            SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, address, cmdText);
            device.Send(pkg);
            if (pkg.result != CmdResult.ACK)
                throw new Exception("cmd error:" + pkg.result);

            byte frame_no = pkg.ReturnTextPackage.Text[3]; //0x98 frame_no
            ms = new System.IO.MemoryStream(1024 * 1024*3);
            for (int i = 1; i <= frame_no; i++)
            {
                cmdText = new byte[] {0x98,mode,g_code_id,(byte)i };

                pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, address, cmdText);

                device.Send(pkg);

                frame = new RGS_SetBackgroundPic_frame(pkg.ReturnTextPackage);

                ms.Write(frame.g_pattern_color, 0, frame.g_pattern_color.Length);

            }

            Bitmap pic = new Bitmap(frame.g_width, frame.g_height);

            ms.Position = 0;

            for(int y =0;y<frame.g_height;y++)
                for (int x = 0; x < frame.g_width; x++)
                {
                   // int r, g, b;
                    //r = ms.ReadByte();
                    //g = ms.ReadByte();
                    //b = ms.ReadByte();
                    pic.SetPixel(x, y, Color.FromArgb(ms.ReadByte(),ms.ReadByte(), ms.ReadByte()));
                }

               desc= System.Text.Encoding.Unicode.GetString(frame.g_desc);

            ms.Dispose();
            return pic;
        }
开发者ID:ufjl0683,项目名称:sshmc,代码行数:45,代码来源:RGS30_Extend.cs

示例9: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     VryImgGen gen = new VryImgGen();
     string verifyCode = gen.CreateVerifyCode(4,0);
     HttpCookie cookie = new HttpCookie("VerifyCode", verifyCode.ToUpper());
     cookie.Expires = DateTime.Now.AddSeconds(3000);//过期时间为60秒
     Response.Cookies.Add(cookie);
     System.Drawing.Bitmap bitmap = gen.CreateImage(verifyCode);
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
     Response.Clear();
     Response.ContentType = "image/Png";
     Response.BinaryWrite(ms.GetBuffer());
     bitmap.Dispose();
     ms.Dispose();
     ms.Close();
     Response.End();
 }
开发者ID:notinmood,项目名称:zlzw.jobsite,代码行数:18,代码来源:VerifyCode.aspx.cs

示例10: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
            response.Clear();
            response.Cache.SetCacheability(HttpCacheability.NoCache);
            response.ContentType = ContentType;

            //Check to see if this is done from bytes or physical location
            //  If you're really paranoid you could set a true/false flag in
            //  the constructor.
            if (ImageBytes != null)
            {
                var stream = new System.IO.MemoryStream(ImageBytes);
                stream.WriteTo(response.OutputStream);
                stream.Dispose();
            }
            else
            {
                response.TransmitFile(SourceFilename);
            }
        }
开发者ID:kyallbarrows,项目名称:LifeguardServer,代码行数:21,代码来源:ImageResult.cs

示例11: Encrypt

 /// <summary> 
 /// 加密数据 
 /// </summary> 
 /// <param name="Text"></param> 
 /// <param name="sKey"></param> 
 /// <returns></returns> 
 public static string Encrypt(string Text, string sKey)
 {
     DESCryptoServiceProvider des = new DESCryptoServiceProvider();
     byte[] inputByteArray;
     inputByteArray = Encoding.Default.GetBytes(Text);
     des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
     des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
     cs.Write(inputByteArray, 0, inputByteArray.Length);
     cs.FlushFinalBlock();
     StringBuilder ret = new StringBuilder();
     foreach (byte b in ms.ToArray())
     {
         ret.AppendFormat("{0:X2}", b);
     }
     cs.Close();
     cs.Dispose();
     ms.Close();
     ms.Dispose();            
     return ret.ToString();
 }
开发者ID:caocf,项目名称:workspace-kepler,代码行数:28,代码来源:DESEncrypt.cs

示例12: AddLayerClassNode

        private void AddLayerClassNode(layerObj layer, TreeNode layernode)
        {
            if ((layer == null) || (layernode == null)) return;
            int iClassCount = layer.numclasses;
            for (int i = 0; i < iClassCount; i++)
            {
                classObj pClass = layer.getClass(i);
                imageObj pSymbolImage = pClass.createLegendIcon(m_pMap, layer, 16, 16);

                byte[] buffer = pSymbolImage.getBytes();
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                ms.Write(buffer, 0, buffer.Length);
                imageListLeg.Images.Add(Image.FromStream(ms));
                ms.Dispose();
                pSymbolImage.Dispose();

                int iIndex = imageListLeg.Images.Count - 1;

                TreeNode subNode2 = new TreeNode("", iIndex, iIndex);
                layernode.Nodes.Add(subNode2);
            }
        }
开发者ID:adsort,项目名称:mfeditor,代码行数:22,代码来源:LegendControl.cs

示例13: TabManagerMain_PageAdded

        private void TabManagerMain_PageAdded(object sender, DevExpress.XtraTabbedMdi.MdiTabPageEventArgs e)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            e.Page.MdiChild.Icon.Save(ms);
            e.Page.Image = Image.FromStream(ms);
            ms.Close(); ms.Dispose();
            //if (e.Page.MdiChild.GetType())
            //{

            //}
        }
开发者ID:EgyFalseX-Nestle,项目名称:NestleMenu,代码行数:11,代码来源:MainFrm.cs

示例14: getData

        public byte[] getData()
        {
            byte[] result = new byte[getNumSamples() * channels * (bitDepth / 8)];
            System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
            System.IO.BinaryWriter wr = new System.IO.BinaryWriter(ms);

            if (bitDepth == 16) {
                for (int i = 0; i < getNumSamples(); i++) {
                    for (int c = 0; c < channels; c++) {
                        //assuming signed
                        wr.Write((short)(samples[c][i] * 32768));
                    }
                }
            } else if (bitDepth == 8) {
                for (int i = 0; i < getNumSamples(); i++) {
                    for (int c = 0; c < channels; c++) {
                        //assuming unsigned
                        wr.Write((byte)(samples[c][i] * 128 + 128));
                    }
                }
            }
            wr.Dispose();
            ms.Dispose();
            return result;
        }
开发者ID:JoePelz,项目名称:DSPProject,代码行数:25,代码来源:WaveFile.cs

示例15: ToImage

    public Image ToImage(System.Drawing.Imaging.ImageFormat format_)
    {
      Chart.DataBind();
      Chart.InvalidateLayers();

      System.IO.MemoryStream ms = new System.IO.MemoryStream();
      Chart.SaveTo(ms, format_);
      Image ret = Image.FromStream(ms);
      ms.Close();
      ms.Dispose();

      return ret;
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:13,代码来源:ChartControlBase.cs


注:本文中的System.IO.MemoryStream.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。