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


C# MemoryStream.ToBytes方法代码示例

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


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

示例1: Invoke

        public void Invoke(Action<string> yield)
        {
            // 203f4a3d71
            // 20713d4a3f
            {
                var m = new ByteArray();

                // !
                m.endian = Endian.LITTLE_ENDIAN;

                m.writeByte(' ');

                //m.endian
                m.writeFloat(0.79);

                var bytes = m.ToMemoryStream().ToBytes();

                var base64 = Convert.ToBase64String(bytes);

                yield(base64);
            }

            // 20713d4a3f
            {
                var m = new MemoryStream();

                m.WriteByte((byte)' ');

                //                Implementation not found for type import :
                //type: System.IO.BinaryWriter
                //method: Void Write(Single)

                var w = new BinaryWriter(m);

                w.Write((float)0.79);

                var bytes = m.ToBytes();

                var base64 = Convert.ToBase64String(bytes);

                yield(base64);
            }
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:43,代码来源:ApplicationSprite.cs

示例2: Main

        public static void Main(string[] args)
        {
            {
                var m = new MemoryStream();

                m.WriteByte((byte)' ');


                var w = new BinaryWriter(m);

                w.Write((float)0.79);

                var bytes = m.ToBytes();

                Console.WriteLine(bytes.ToHexString());

            }

            RewriteToUltraApplication.AsProgram.Launch(typeof(Application));
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:20,代码来源:Program.cs

示例3: Convert

        public static void Convert(TransportMessage message, IBytesMessage toSend, IMessageSerializer serializer)
        {
            byte[] body;
            if (message.Body == null && message.BodyStream != null)
            {
                body = message.BodyStream.ToBytes();
            }
            else
            {
                var stream = new MemoryStream();
                serializer.Serialize(message.Body, stream);
                body = stream.ToBytes();
            }

            toSend.WriteBytes(body);

            // TODO: clarify usage of JMSCorrelationID
            toSend.JMSCorrelationID = message.CorrelationId;
            toSend.JMSDeliveryMode = message.Recoverable ? DeliveryMode.Persistent : DeliveryMode.NonPersistent;
            toSend.SetStringProperty(HEADER_RETURNADDRESS, message.ReturnAddress);
            toSend.SetStringProperty(HEADER_IDFORCORRELATION, message.IdForCorrelation);
            toSend.SetStringProperty(HEADER_WINDOWSIDENTITYNAME, message.WindowsIdentityName);
            toSend.SetIntProperty(HEADER_MESSAGEINTENT, (int) message.MessageIntent);

            //TODO: set message expiration
            //toSend.JMSReplyTo = new Destination message.ReplyToAddress;
            //if (message.TimeToBeReceived < MessageQueue.InfiniteTimeout)
            //toSend.JMSExpiration = (long) UTCNow.message.TimeToBeReceived.TotalMilliseconds;

            if (message.Headers == null)
                message.Headers = new List<HeaderInfo>();

            var nsbHeaderKeys = new List<string>();
            foreach (var keyValue in message.Headers)
            {
                toSend.SetStringProperty(keyValue.Key.ToXmsFriendly(), keyValue.Value);
                nsbHeaderKeys.Add(keyValue.Key.ToXmsFriendly());
            }
            toSend.SetStringProperty(HEADER_NBSKEYS, WrapKeys(nsbHeaderKeys));
        }
开发者ID:sasha-uk,项目名称:NServiceBus.Xms.2,代码行数:40,代码来源:XmsUtilities.cs

示例4: Dequeue

        public Stream Dequeue(Guid messageId)
        {
            ResetUnderlyingMessageData();

            lock (padlock)
            {
                try
                {
                    using (databaseConnectionFactory.Create(dataSource))
                    {
                        var row = databaseGateway.GetSingleRowUsing(
                            dataSource,
                            RawQuery.CreateFrom(dequeueIdQueryStatement).AddParameterValue(QueueColumns.MessageId,
                                                                                           messageId));

                        if (row == null)
                        {
                            return null;
                        }

                        underlyingMessageData = row;

                        using (var stream = new MemoryStream((byte[]) row["MessageBody"]))
                        {
                            underlyingMessageData = new MemoryStream(stream.ToBytes());

                            return (Stream) underlyingMessageData;
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Debug(string.Format("Could not dequeue message from queue '{0}'.  Exception: {1}.  Query: {2}",
                                            Uri, ex.Message, createQuery));

                    throw;
                }
            }
        }
开发者ID:nnyamhon,项目名称:shuttle-esb,代码行数:39,代码来源:SqlQueue.cs

示例5: DownloadBlob

        /// <summary>
        /// Downloads the BLOB.
        /// </summary>
        /// <param name="blob">The BLOB.</param>
        /// <param name="fetchAttribute">if set to <c>true</c> [fetch attribute].</param>
        /// <param name="metaData">The meta data.</param>
        /// <returns>System.Byte[].</returns>
        public static byte[] DownloadBlob(CloudBlockBlob blob, bool fetchAttribute, out IDictionary<string, string> metaData)
        {
            try
            {
                blob.CheckNullObject("blob");

                if (fetchAttribute)
                {
                    blob.FetchAttributes();
                    metaData = blob.Metadata;
                }
                else
                {
                    metaData = null;
                }

                var msRead = new MemoryStream { Position = 0 };
                using (msRead)
                {
                    blob.DownloadToStream(msRead);
                    return msRead.ToBytes();
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle("DownloadBlob", blob.Uri.ToString());
            }
        }
开发者ID:rynnwang,项目名称:CommonSolution,代码行数:35,代码来源:AzureStorageManager.cs

示例6: GetBytes

        /// <summary>
        /// Gets the bytes.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="imageFormat">The image format.</param>
        /// <param name="qualityLevel">The quality level.
        /// <remarks>
        /// A quality level of 0 corresponds to the greatest compression, and a quality level of 100 corresponds to the least compression.
        /// https://msdn.microsoft.com/library/bb882583(v=vs.110).aspx
        /// </remarks></param>
        /// <returns>System.Byte[].</returns>
        /// <exception cref="OperationFailureException">GetBytes</exception>
        public static byte[] GetBytes(this Bitmap image, ImageFormat imageFormat = null, long qualityLevel = 100)
        {
            try
            {
                image.CheckNullObject("image");

                if (imageFormat == null)
                {
                    imageFormat = ImageFormat.Jpeg;
                }

                if (qualityLevel > 100 || qualityLevel < 1)
                {
                    qualityLevel = 100;
                }

                using (var memoryStream = new MemoryStream())
                {
                    var jpegEncoder = GetImageEncoder(imageFormat);
                    var encoder = Encoder.Quality;
                    var encoderParameters = new EncoderParameters(1);

                    var myEncoderParameter = new EncoderParameter(encoder, qualityLevel);
                    encoderParameters.Param[0] = myEncoderParameter;
                    image.Save(memoryStream, jpegEncoder, encoderParameters);

                    return memoryStream.ToBytes();
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle();
            }
        }
开发者ID:rynnwang,项目名称:CommonSolution,代码行数:46,代码来源:DrawingExtension.cs

示例7: CacheImage

 private static void CacheImage(string url, Bitmap bitmap)
 {
     string imagePath = GetProfileImagePath(url);
     if (!File.Exists(imagePath))
     {
         ByteBuffer byteBuffer = ByteBuffer.Allocate(bitmap.ByteCount);
         bitmap.CopyPixelsToBuffer(byteBuffer);
         MemoryStream ms = new MemoryStream();
         bitmap.Compress(Bitmap.CompressFormat.Png, 100, ms);
         byte[] bytes = ms.ToBytes();
         using (var fs = File.Create(imagePath))
         {
             fs.Write(bytes,0,bytes.Length);
         }
     }
 }
开发者ID:ServiceStackApps,项目名称:AndroidXamarinChat,代码行数:16,代码来源:UIHelpers.cs


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