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


C# DataReader.ReadBytes方法代码示例

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


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

示例1: ReceiveImage

        private async void ReceiveImage(StreamSocket socket)
        {
            UpdateStatus("Empfange Daten...");

            // DataReader erzeugen, um arbeiten mit Bytes zu vereinfachen
            var reader = new DataReader(socket.InputStream);

            // Anzahl der Bytes abrufen, aus denen das Bild besteht
            // Anzahl = int = 4 Bytes => 4 Bytes vom Socket laden
            await reader.LoadAsync(4);
            int imageSize = reader.ReadInt32();

            // Bytearray des Bildes laden
            await reader.LoadAsync((uint)imageSize);
            byte[] imageBytes = new byte[imageSize];
            reader.ReadBytes(imageBytes);

            // Bytearray in Stream laden und anzeigen
            Dispatcher.BeginInvoke(() =>
            {
                using (var ms = new MemoryStream(imageBytes))
                {
                    var image = new BitmapImage();
                    image.SetSource(ms);

                    ReceivedImage.Source = image;
                }
            });
            UpdateStatus("Bild empfangen.");

            // Ressourcen freigeben
            reader.Dispose();
        }
开发者ID:GregOnNet,项目名称:WP8BookSamples,代码行数:33,代码来源:ClientPage.xaml.cs

示例2: StreamSkeleton

		private async void StreamSkeleton()
		{
			try
			{
                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
					BinaryReader br = new BinaryReader(ms);

					SkeletonFrameData frame = br.ReadSkeletonFrame();

					SkeletonFrameReadyEventArgs args = new SkeletonFrameReadyEventArgs { SkeletonFrame = frame };
					SkeletonFrame = frame;

					Context.Send(delegate
					{
						if(SkeletonFrameReady != null)
							SkeletonFrameReady(this, args);
					}, null);
				}
			}
			catch(IOException)
			{
                Disconnect();
			}
		}
开发者ID:kaorun55,项目名称:KinectService,代码行数:35,代码来源:SkeletonClient.cs

示例3: ReceiveMessages

        /// <summary>
        /// Receive message through bluetooth.
        /// </summary>
        protected async Task<byte[]> ReceiveMessages(DataReader dataReader)
        {
            try
            {
                
                // Read the message. 
                List<Byte> all = new List<byte>();

                while (true)
                {
                    var bytesAvailable = await dataReader.LoadAsync(1000);
                    var byteArray = new byte[bytesAvailable];
                    dataReader.ReadBytes(byteArray);
                    if (byteArray.Length > 0 && byteArray[0] != byte.MinValue)
                    {
                        if (OnDataRead != null) OnDataRead(byteArray);
                        return byteArray;
                    }

                    Thread.Sleep(100);
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return null;
        }
开发者ID:nothingmn,项目名称:zVirtualScenes-Client,代码行数:32,代码来源:BaseChannel.cs

示例4: save_Video

        private async void save_Video(object sender, RoutedEventArgs e)
        {
            // Adding try catch block in case of occurence of an exception
            try
            {
                // Creating object of FileSavePicker and adding few values to the properties of the object.
                FileSavePicker fs = new FileSavePicker();
                fs.FileTypeChoices.Add("Video", new List<string>() { ".mp4",".3gp" });
                fs.DefaultFileExtension = ".mp4";
                fs.SuggestedFileName = "Video" + DateTime.Today.ToString();
                fs.SuggestedStartLocation = PickerLocationId.VideosLibrary;

                // Using storagefile object defined earlier in above method to save the file using filesavepicker.
                fs.SuggestedSaveFile = sf;

                // Saving the file
                var s = await fs.PickSaveFileAsync();
                if (s != null)
                {
                    using (var dataReader = new DataReader(rs.GetInputStreamAt(0)))
                    {
                        await dataReader.LoadAsync((uint)rs.Size);
                        byte[] buffer = new byte[(int)rs.Size];
                        dataReader.ReadBytes(buffer);
                        await FileIO.WriteBytesAsync(s, buffer);
                    }
                }
            }
            catch (Exception ex)
            {
                var messageDialog = new MessageDialog("Something went wrong.");
                await messageDialog.ShowAsync();
            }
        }
开发者ID:sarthakbhol,项目名称:Windows10AppSamples,代码行数:34,代码来源:MainPage.xaml.cs

示例5: Read

 private async Task<RfidReaderResult> Read()
 {
     RfidReaderResult retvalue = new RfidReaderResult();
     var dataReader = new DataReader(_rfidReader.InputStream);
     try
     {
         SetStatus("Awaiting Data from RFID Reader");
         var numBytesRecvd = await dataReader.LoadAsync(1024);
         retvalue.Result = new byte[numBytesRecvd];
         if (numBytesRecvd > 0)
         {
             SetStatus("Data successfully read from RFID Reader");
             dataReader.ReadBytes(retvalue.Result);
             retvalue.IsSuccessful = true;
             retvalue.Message = "Data successfully read from RFID Reader";
         }
     }
     catch (Exception ex)
     {
         retvalue.IsSuccessful = false;
         retvalue.Message = ex.Message;
     }
     finally
     {
         if (dataReader != null)
         {
             dataReader.DetachStream();
             dataReader = null;
         }
     }
     return retvalue;
 }
开发者ID:codingbandit,项目名称:CottonwoodSerialTester,代码行数:32,代码来源:MainPage.xaml.cs

示例6: ConvertIRandomAccessStreamByte

 private static async Task<byte[]> ConvertIRandomAccessStreamByte(IRandomAccessStream stream)
 {
     DataReader read = new DataReader(stream.GetInputStreamAt(0));
     await read.LoadAsync((uint)stream.Size);
     byte[] temp = new byte[stream.Size];
     read.ReadBytes(temp);
     return temp;
 }
开发者ID:GuojieLin,项目名称:CnBlogs,代码行数:8,代码来源:ImageStorageHelper.cs

示例7: GetPhotoBits

 /// <summary>
 /// Returns a byte array with the content of the stream.
 /// </summary>
 /// <param name="stream">stream to get bytes for</param>
 /// <returns>awaitable byte array</returns>
 public static async Task<byte[]> GetPhotoBits(IRandomAccessStream stream)
 {
     Debug.Assert(stream != null, "GetPhotoBits should not be called with a null stream.");
     var reader = new DataReader(stream.GetInputStreamAt(0));
     var bytes = new byte[stream.Size];
     await reader.LoadAsync((uint)stream.Size);
     reader.ReadBytes(bytes);
     return bytes;
 }
开发者ID:fireelf,项目名称:Winuibuh,代码行数:14,代码来源:OcrClientUtils.cs

示例8: ColorThread

		private async void ColorThread()
		{
			try
			{
                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;
                reader.ByteOrder = ByteOrder.LittleEndian;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
					BinaryReader br = new BinaryReader(ms);

                    ColorFrameReadyEventArgs args = new ColorFrameReadyEventArgs();
                    ColorFrameData cfd = new ColorFrameData();

                    cfd.Format = (ImageFormat)br.ReadInt32();
					cfd.ImageFrame = br.ReadColorImageFrame();

                    MemoryStream msData = new MemoryStream( bytes, (int)ms.Position, (int)(ms.Length - ms.Position) );
                    if (cfd.Format == ImageFormat.Raw)
                    {
                        cfd.RawImage = ms.ToArray();
                    }
                    else
                    {
                        InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
                        DataWriter dw = new DataWriter(ras.GetOutputStreamAt(0));
                        dw.WriteBytes(msData.ToArray());
                        await dw.StoreAsync();   

                        // Set to the image
                        BitmapImage bImg = new BitmapImage();
                        bImg.SetSource(ras);
                        cfd.BitmapImage = bImg;
                    }

					ColorFrame = cfd;
					args.ColorFrame = cfd;

                    if (ColorFrameReady != null)
                    {
                        ColorFrameReady(this, args);
                    }
				}
			}
			catch(IOException)
			{
				Disconnect();
			}
		}
开发者ID:kaorun55,项目名称:KinectService,代码行数:57,代码来源:ColorClient.cs

示例9: Receive

        public string Receive()
        {
            IInputStream istream = this.streamSocket.InputStream;
            var dataReader = new DataReader(istream);

            byte[] msgSizeByteArray = new byte[4];
            dataReader.LoadAsync(4).AsTask().Wait();
            dataReader.ReadBytes(msgSizeByteArray);

            int msgSize = Helpers.byteArrayToInt(msgSizeByteArray);

            byte[] msgByteArray = new byte[msgSize];
            dataReader.LoadAsync((uint) msgSize).AsTask().Wait();
            dataReader.ReadBytes(msgByteArray);

            string message = Helpers.byteArrayToString(msgByteArray);
            return message;
        }
开发者ID:OkayX6,项目名称:BroadcastConsole,代码行数:18,代码来源:TcpConnection.cs

示例10: UploadActivityAsync

        /// <summary>
        /// Uploads an activity.
        /// </summary>
        /// <param name="file">The path to the activity file on your local hard disk.</param>
        /// <param name="dataFormat">The format of the file.</param>
        /// <param name="activityType">The type of the activity.</param>
        /// <returns>The status of the upload.</returns>
        public async Task<UploadStatus> UploadActivityAsync(StorageFile file, DataFormat dataFormat, ActivityType activityType = ActivityType.Ride)
        {
            String format = String.Empty;

            switch (dataFormat)
            {
                case DataFormat.Fit:
                    format = "fit";
                    break;
                case DataFormat.FitGZipped:
                    format = "fit.gz";
                    break;
                case DataFormat.Gpx:
                    format = "gpx";
                    break;
                case DataFormat.GpxGZipped:
                    format = "gpx.gz";
                    break;
                case DataFormat.Tcx:
                    format = "tcx";
                    break;
                case DataFormat.TcxGZipped:
                    format = "tcx.gz";
                    break;
            }
           
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("Authorization", String.Format("Bearer {0}", Authentication.AccessToken));

            MultipartFormDataContent content = new MultipartFormDataContent();

            byte[] fileBytes = null;
            using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
            {
                fileBytes = new byte[stream.Size];
                using (DataReader reader = new DataReader(stream))
                {
                    await reader.LoadAsync((uint)stream.Size);
                    reader.ReadBytes(fileBytes);
                }
            }

            var byteArrayContent = new ByteArrayContent(fileBytes);

            content.Add(byteArrayContent, "file", file.Name);

            HttpResponseMessage result = await client.PostAsync(
                String.Format("https://www.strava.com/api/v3/uploads?data_type={0}&activity_type={1}",
                format,
                activityType.ToString().ToLower()),
                content);

            String json = await result.Content.ReadAsStringAsync();

            return Unmarshaller<UploadStatus>.Unmarshal(json);
        }
开发者ID:TiBall,项目名称:stravadotnet,代码行数:63,代码来源:UploadClient.cs

示例11: GetByteFromFileAsync

 public async static Task<Byte[]> GetByteFromFileAsync(this IRandomAccessStream stream)
 {
     using (var dataReader = new DataReader(stream))
     {
         var bytes = new byte[stream.Size];
         await dataReader.LoadAsync((uint)stream.Size);
         dataReader.ReadBytes(bytes);
         return bytes;
     }
 }
开发者ID:giggio,项目名称:multassociais-windowsapps,代码行数:10,代码来源:Entensoes.cs

示例12: IRandomAccessStreamToByteArr

        public static async Task<byte[]> IRandomAccessStreamToByteArr(IRandomAccessStream irStream)
        {
            DataReader reader = new Windows.Storage.Streams.DataReader(irStream.GetInputStreamAt(0));
            await reader.LoadAsync((uint)irStream.Size);

            byte[] pixels = new byte[irStream.Size];
            reader.ReadBytes(pixels);

            return pixels;
        }
开发者ID:yjlintw,项目名称:YJToolkit,代码行数:10,代码来源:FileConvert.cs

示例13: GetPhotoBytesAsync

        public async Task<byte[]> GetPhotoBytesAsync(StorageFile file)
        {
            IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);
            var reader = new Windows.Storage.Streams.DataReader(fileStream.GetInputStreamAt(0));
            await reader.LoadAsync((uint)fileStream.Size);

            byte[] pixels = new byte[fileStream.Size];
            reader.ReadBytes(pixels);
            return pixels;
        }
开发者ID:xbfish,项目名称:Simple-Windows-8-App,代码行数:10,代码来源:MainPage.xaml.cs

示例14: OpenFile

 private async Task<uint> OpenFile(string fileName)
 {
     StorageFolder myStorageFolder = KnownFolders.DocumentsLibrary;
     myFile = await myStorageFolder.GetFileAsync("ECHelper Files\\" + fileName+".ech");
     readStream = await myFile.OpenAsync(FileAccessMode.Read);
     fileReader = new DataReader(readStream);
     count = await fileReader.LoadAsync((uint)readStream.Size);
     data = new byte[count];
     fileReader.ReadBytes(data);
     return count;
 }
开发者ID:whuacn,项目名称:echelper,代码行数:11,代码来源:ECGReader.cs

示例15: RenderThumbnailAsync

 public async Task RenderThumbnailAsync(StorageFile thumb, int scaleWidht, int scaleHeight)
 {
     ImageStream inputStream = await composition.GetThumbnailAsync(TimeSpan.Zero, scaleWidht, scaleHeight, VideoFramePrecision.NearestFrame);
     using (DataReader reader = new DataReader(inputStream.GetInputStreamAt(0)))
     {
         await reader.LoadAsync((uint)inputStream.Size);
         byte[] buffer = new byte[(uint)inputStream.Size];
         reader.ReadBytes(buffer);
         await FileIO.WriteBytesAsync(thumb, buffer);
     }
 }
开发者ID:Ontropix,项目名称:slow-camera,代码行数:11,代码来源:VideoTrimmer.cs


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