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


C# Byte.AsBuffer方法代码示例

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


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

示例1: OnProcess

        protected override void OnProcess(PixelRegion sourcePixelRegion, PixelRegion targetPixelRegion)
        {
            if(Mask == null)
            {
                //copy all pixel
                Array.Copy(sourcePixelRegion.ImagePixels,targetPixelRegion.ImagePixels,sourcePixelRegion.ImagePixels.Length);
                return;
            }

            //create grayscale buffer
            var buffer = new Byte[(int)(sourcePixelRegion.Bounds.Width*sourcePixelRegion.Bounds.Height)];

            //interface grayscale buffer
            var bitmapMask = new Bitmap(
                new Windows.Foundation.Size(sourcePixelRegion.Bounds.Width, sourcePixelRegion.Bounds.Height),
                ColorMode.Gray8,
                (uint)sourcePixelRegion.Bounds.Width,
                buffer.AsBuffer());
            //load grayscale buffer
            Mask.GetBitmapAsync(bitmapMask,OutputOption.Stretch).AsTask().Wait();

            sourcePixelRegion.ForEachRow((index, width, pos) =>
            {
                for (int x = 0; x < width; ++x, ++index)
                {
                    uint color = sourcePixelRegion.ImagePixels[index];

                    // copy grayscale buffer to alpha channel
                    var a = buffer[index];
                    uint rgb = (color & 0x00FFFFFF);
                    targetPixelRegion.ImagePixels[index] = rgb | (uint)(a << 24);
                }
            });
        }
开发者ID:Nokia-Developer-Community-Projects,项目名称:wp8-sample,代码行数:34,代码来源:GrayscaleToAlphaEffect.cs

示例2: SaveImageToCacheAndGetImage2

        public static async Task<BitmapImage> SaveImageToCacheAndGetImage2(Byte[] imageArray, string fileName)
        {
            try
            {
                var folder = ApplicationData.Current.LocalFolder;

                var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                var bitmapImage = new BitmapImage();

                using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(imageArray.AsBuffer());

                    stream.Seek(0);
                    await bitmapImage.SetSourceAsync(stream);
                    stream.Dispose();
                }


                return bitmapImage;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return null;
            }
        }
开发者ID:DXFrance,项目名称:OfficeTicTacToe,代码行数:28,代码来源:ImageHelper.cs

示例3: PostSocketRead

 private void PostSocketRead(Int32 length)
 {
     try
     {
         var buffer = new Byte[length];
         var asyncOperationWithProgress = _socket.InputStream.ReadAsync(buffer.AsBuffer(), (UInt32)length, InputStreamOptions.Partial);
         asyncOperationWithProgress.Completed += (info, status) =>
         {
               switch (status)
             {
                 case AsyncStatus.Completed:
                 case AsyncStatus.Error:
                 {
                     try
                     {
                         IBuffer results = info.GetResults();
                         OnDataReadCompletion(results.Length, DataReader.FromBuffer(results));
                     }
                     catch (Exception exception)
                     {
                         Debug.WriteLine(String.Concat("Read operation failed:  ", exception.Message));
                     }
                     break;
                 }
             }
         };
     }
     catch (Exception exception1)
     {
         Debug.WriteLine(String.Concat("failed to post a read failed with error:  ", exception1.Message));
     }
 }
开发者ID:xesf,项目名称:Sphero-WinPhone8-SDK,代码行数:32,代码来源:RobotSession.cs


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