本文整理汇总了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();
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}