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


C# MemoryStream.GetBuffer方法代码示例

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


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

示例1: Test_Image_ByteArray

    public void Test_Image_ByteArray()
    {
      using (Image img = Image.FromFile(Files.Coders.PageTIF))
      {
        byte[] bytes = null;
        using (MemoryStream memStream = new MemoryStream())
        {
          img.Save(memStream, ImageFormat.Tiff);
          bytes = memStream.GetBuffer();
        }

        using (MagickImage image = new MagickImage(bytes))
        {
          image.CompressionMethod = CompressionMethod.Group4;

          using (MemoryStream memStream = new MemoryStream())
          {
            image.Write(memStream);
            memStream.Position = 0;

            using (MagickImage before = new MagickImage(Files.Coders.PageTIF))
            {
              using (MagickImage after = new MagickImage(memStream))
              {
                Assert.AreEqual(0.0, before.Compare(after, ErrorMetric.RootMeanSquared));
              }
            }
          }
        }
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:31,代码来源:TiffTests.cs

示例2: Build

		public override byte[] Build()
		{
			MemoryStream temp = new MemoryStream(128);
			Writer writer = new Writer(temp);

			writer.Seek(0x62, SeekOrigin.Begin);
			writer.WriteString(Login, Encoding.ASCII);
			writer.Seek(0x70, SeekOrigin.Begin);
			writer.WriteString(Password, Encoding.ASCII);


			MemoryStream ms = new MemoryStream(168);
			writer = new Writer(ms);

			writer.Write(Id);
			writer.Write(Encrypt(temp.GetBuffer()));
			writer.Write(SessionId);
			writer.Write(GameGuard);

			ulong chk = Utils.CheckSum(ms.GetBuffer(), 160);
			writer.Write((byte)(chk & 0xff));
			writer.Write((byte)(chk >> 0x08 & 0xff));
			writer.Write((byte)(chk >> 0x10 & 0xff));
			writer.Write((byte)(chk >> 0x18 & 0xff));
			writer.Write((Int32)0);

			return ms.GetBuffer();
		}
开发者ID:EligiusSantori,项目名称:L2Apf.NET,代码行数:28,代码来源:RequestAuthLogin.cs

示例3: Button1_Click

        protected void Button1_Click(object sender, EventArgs e)
        {
            Page.Title = "Contact List";
            MemoryStream PDFData = new MemoryStream();

            // step 1: creation of a document-object
            Document document = new Document();

            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file

            PdfWriter.GetInstance(document, PDFData);

            // step 3: we open the document
            document.Open();

            // step 4: we add a paragraph to the document
            document.Add(new Paragraph(DateTime.Now.ToString()));
            Contact oContact = new Contact();
            DataTable dtContact = oContact.LoadAll();
            int numRow = dtContact.Rows.Count;
            int numCol = 5;
            iTextSharp.text.Table aTable = new iTextSharp.text.Table(numCol, numRow);
            aTable.AutoFillEmptyCells = true;
            aTable.Padding = 1;
            aTable.Spacing = 1;

            Cell cell = new Cell(new Phrase("Contact List", FontFactory.GetFont(FontFactory.TIMES, 14, Font.BOLD)));
            cell.Header = true;
            cell.Colspan = numCol;
            cell.BackgroundColor = Color.LIGHT_GRAY;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;

            aTable.AddCell(cell);

            for (int i = 0; i < dtContact.Rows.Count; i++)
            {
                for (int n = 1; n <= numCol; n++)
                    aTable.AddCell(dtContact.Rows[i][n].ToString());

            }
            document.Add(aTable);
            // step 5: we close the document
            document.Close();

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/pdf";
            Response.Charset = string.Empty;
            Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
            Response.AddHeader("Content-Disposition",
                "attachment; filename=" + Title.Replace(" ", "").Replace(":", "-") + ".pdf");

            Response.OutputStream.Write(PDFData.GetBuffer(), 0, PDFData.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.End();
        }
开发者ID:wjkong,项目名称:MicNets,代码行数:60,代码来源:WebForm1.aspx.cs

示例4: ReceiveMessage

        protected string ReceiveMessage()
        {
            var buffer = new MemoryStream();
            int @byte;
            bool possibleDelimiterIsComing;
            var possibleDelimiterCount = 0;

            while ((@byte = stream.ReadByte()) != -1)
            {
                buffer.WriteByte((byte)@byte);

                if (@byte == this.delimiterBytes[possibleDelimiterCount])
                {
                    possibleDelimiterIsComing = true;
                    possibleDelimiterCount++;
                }
                else
                {
                    possibleDelimiterIsComing = false;
                    possibleDelimiterCount = 0;
                }

                if (possibleDelimiterIsComing && this.delimiterBytes.Length == possibleDelimiterCount)
                {
                    // complete message received, return removing the delimiters
                    return StreamEncoding.GetString(
                        buffer.GetBuffer(),
                        0,
                        (int)(buffer.Length - this.delimiterBytes.Length));
                }
            }

            // return incomplete message
            return StreamEncoding.GetString(buffer.GetBuffer());
        }
开发者ID:joaofx,项目名称:HumbleNetwork,代码行数:35,代码来源:DelimitedStream.cs

示例5: EntryMetadataUrlRoundTrip

        public void EntryMetadataUrlRoundTrip()
        {
            var stream = new MemoryStream();
            var writerRequestMemoryMessage = new InMemoryMessage();
            writerRequestMemoryMessage.Stream = stream;
            writerRequestMemoryMessage.SetHeader("Content-Type", "application/json");

            var writerSettings = new ODataMessageWriterSettings() {Version = ODataVersion.V4, DisableMessageStreamDisposal = true};
            writerSettings.ODataUri = new ODataUri() {ServiceRoot = new Uri("http://christro.svc/")};

            var messageWriter = new ODataMessageWriter((IODataResponseMessage)writerRequestMemoryMessage, writerSettings, this.model);
            var organizationSetWriter = messageWriter.CreateODataEntryWriter(this.organizationsSet);
            var odataEntry = new ODataEntry(){ TypeName = ModelNamespace + ".Corporation" };
            odataEntry.Property("Id", 1);
            odataEntry.Property("Name", "");
            odataEntry.Property("TickerSymbol", "MSFT");

            organizationSetWriter.WriteStart(odataEntry);
            organizationSetWriter.WriteEnd();

            var readerPayloadInput = Encoding.UTF8.GetString(stream.GetBuffer());
            Console.WriteLine(readerPayloadInput);

            var readerResponseMemoryMessage = new InMemoryMessage();
            readerResponseMemoryMessage.Stream = new MemoryStream(stream.GetBuffer());
            readerResponseMemoryMessage.SetHeader("Content-Type", "application/json");

            var messageReader = new ODataMessageReader((IODataResponseMessage)readerResponseMemoryMessage, new ODataMessageReaderSettings() {MaxProtocolVersion = ODataVersion.V4, DisableMessageStreamDisposal = true}, this.model);
            var organizationReader = messageReader.CreateODataEntryReader(this.organizationsSet, this.organizationsSet.EntityType());
            organizationReader.Read().Should().Be(true);
            organizationReader.Item.As<ODataEntry>();
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:32,代码来源:MetadataUriRoundTripTests.cs

示例6: Image

 public Image(MemoryStream imageStream)
     : this()
 {
     // Added new property to hold the stream
     ImageStream = new MemoryStream();
     ImageStream.Write(imageStream.GetBuffer(), 0, imageStream.GetBuffer().Length);
     Name = String.Empty;         // When no filename, we'll look for the stream.
 }
开发者ID:jgshumate1,项目名称:Migradoc,代码行数:8,代码来源:Image.cs

示例7: UpgradeLayoutFile

        public static ActionResult UpgradeLayoutFile(Session session)
        {
            string appData = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TraceLab");
            var path = System.IO.Path.Combine(appData, "layout.xml");

            bool resetLayout = false;
            try
            {
                if (System.IO.File.Exists(path))
                {
                    session.Log("Upgrading layout file.");

                    using (MemoryStream memStream = new MemoryStream())
                    {
                        using (var fileStream = File.OpenRead(path))
                        {
                            memStream.SetLength(fileStream.Length);
                            fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
                            memStream.Flush();
                            fileStream.Close();
                        }

                        UpgradeLayoutToCurrentVersion(memStream);

                        // The memory stream has been transformed in place, it is now time to copy it back to the file.
                        using (var fileStream = File.OpenWrite(path))
                        {
                            fileStream.Write(memStream.GetBuffer(), 0, (int)memStream.Length);
                            fileStream.SetLength(memStream.Length);
                            fileStream.Close();
                        }
                    }

                    session.Log("Done upgrading layout file.");
                }
            }
            catch (Exception e)
            {
                session.Log("Exception occurred: {0}\n{1}", e.Message, e.StackTrace);
                resetLayout = true;
            }

            if (resetLayout)
            {
                try
                {
                    session.Log("Resetting layout");
                    System.IO.File.Delete(path);
                }
                catch (Exception)
                {
                    return ActionResult.Failure;
                }
            }

            return ActionResult.Success;
        }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:57,代码来源:LayoutUpgrades.cs

示例8: CopyTo_MultiWithFirstLast

 public void CopyTo_MultiWithFirstLast()
 {
     using (MemoryStream src = new MemoryStream(new byte[] {0, 1, 2, 3, 5}), dst = new MemoryStream())
       {
     StreamHelpers.CopyTo(src, dst, 1, 3);
     Assert.AreEqual(3, dst.Length);
     Assert.AreEqual(1, dst.GetBuffer()[0]);
     Assert.AreEqual(2, dst.GetBuffer()[1]);
     Assert.AreEqual(3, dst.GetBuffer()[2]);
       }
 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:11,代码来源:CopyToTest.cs

示例9: ReadFully

 public static byte[] ReadFully(Stream input)
 {
     using (MemoryStream tempStream = new MemoryStream())
     {
         Copy(input, tempStream);
         if (tempStream.Length == tempStream.GetBuffer().Length)
         {
             return tempStream.GetBuffer();
         }
         return tempStream.ToArray();
     }
 }
开发者ID:gourdon,项目名称:C-,代码行数:12,代码来源:StreamUtilNoExtensions.cs

示例10: InsertBLOBImage

        public int InsertBLOBImage(Bitmap image)
        {
            MemoryStream stream = new MemoryStream();
            image.Save(stream, ImageFormat.Png);

            return insertBLOB(stream.GetBuffer());
        }
开发者ID:NoxHarmonium,项目名称:enform,代码行数:7,代码来源:SQLiteDatabase.cs

示例11: ExpandString

        /// <summary>
        /// Expands (de-compresses) a string.
        /// </summary>
        /// <param name="value">The string to expanded.</param>
        /// <returns>The expanded string.</returns>
        public string ExpandString(string value)
        {
            // The input value must be non-null
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var outputData = string.Empty;
            var inputData = Convert.FromBase64String(value);
            using (var inputStream = new MemoryStream(inputData))
            {
                using (var outputStream = new MemoryStream())
                {
                    // Zip the string
                    using (var zipStream = new InflaterInputStream(inputStream))
                    {
                        zipStream.IsStreamOwner = false;
                        StreamUtils.Copy(zipStream, outputStream, new byte[4096]);
                    }

                    // Convert to a string
                    outputData = UTF8Encoding.UTF8.GetString(outputStream.GetBuffer(), 0, Convert.ToInt32(outputStream.Length));
                }
            }

            // Return the compressed string
            return outputData;
        }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:34,代码来源:ZipCompressionService.cs

示例12: Write

 public override void Write(Stream stream)
 {
     MemoryStream ms = new MemoryStream();
     Icon.ToBitmap().Save(ms, ImageFormat.Png);
     byte[] buffer = ms.GetBuffer();
     stream.Write(buffer, 0, (int) ms.Length);
 }
开发者ID:Jamedjo,项目名称:IconLib,代码行数:7,代码来源:PNGEncoder.cs

示例13: Serialize

        public override string Serialize(MemberInfo storageType, object value,
            ISerializationOperator serializationOperator) {

            if (value == null) return "null";

            if (_serializer == null) {
                throw new InvalidOperationException("No protobuf-net serializer is loaded");
            }

            UnityObjectReferenceHack.ActiveOperator = serializationOperator;

            using (var stream = new MemoryStream()) {
                _serializer.Serialize(stream, value, new SerializationContext() {
                    Context = serializationOperator
                });

                UnityObjectReferenceHack.ActiveOperator = null;

#if !UNITY_EDITOR && UNITY_WINRT
                return Convert.ToBase64String(stream.ToArray(), 0, (int)stream.Length);
#else
                return Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length);
#endif
            }
        }
开发者ID:Boxxxx,项目名称:clicker,代码行数:25,代码来源:ProtoBufNetSerializer.cs

示例14: SetValue

        private bool SetValue(object currentValue, out object newValue)
        {
            DTE dte = this.GetService<DTE>(true);
            IDictionaryService dictionaryService = (IDictionaryService)ServiceHelper.GetService(this, typeof(IDictionaryService));

            try
            {
                if (!string.IsNullOrEmpty(RecipeArgument))
                {

                    string argumentvalue = dictionaryService.GetValue(RecipeArgument).ToString();
                    Version v = new Version(argumentvalue);
                    if (v != null)
                    {
                        byte[] bytes;
                        long length = 0;
                        MemoryStream ws = new MemoryStream();
                        BinaryFormatter sf = new BinaryFormatter();
                        sf.Serialize(ws, v);
                        length = ws.Length;
                        bytes = ws.GetBuffer();
                        newValue = Convert.ToBase64String(bytes, 0, bytes.Length, Base64FormattingOptions.None);
                        return true;
                    }
                }
            }
            catch { }
            //string projectId = currentProject.

            newValue = "";
            return false;
        }
开发者ID:sunday-out,项目名称:SharePoint-Software-Factory,代码行数:32,代码来源:SerializedVersionProvider.cs

示例15: Main

 static void Main(string[] args)
 {
     string quit = "n";
     while (quit == "n")
     {
         ITransport transport = TcpTransport.CreateTransport(45459);
         if (transport != null)
         {
             IEvent e = new TcpEvent((int)EventId.Media, null);
             BinaryFormatter bf = new BinaryFormatter();
             MemoryStream mem = new MemoryStream();
             bf.Serialize(mem, e);
             transport.Send(mem.GetBuffer());
             Console.WriteLine("Quit?(y/n)");
             quit = Console.ReadLine();
             transport.Close();
             //if (quit != "n")
             //{
             //    Console.WriteLine("send disconned event to Server to close the server");
             //    IEvent d = new TcpEvent((int)EventId.Disconnect, null);
             //    BinaryFormatter bfd = new BinaryFormatter();
             //    MemoryStream memd = new MemoryStream();
             //    bfd.Serialize(memd, d);
             //    transport.Send(memd.GetBuffer());
             //    transport.Close();
             //}
         }
     }
 }
开发者ID:anjing,项目名称:TCPChannel,代码行数:29,代码来源:Program.cs


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