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


C# IStorageFile.OpenReadAsync方法代码示例

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


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

示例1: GenerateThumbnail

        private static async Task<Uri> GenerateThumbnail(IStorageFile file)
        {
            using (var fileStream = await file.OpenReadAsync())
            {
                // decode the file using the built-in image decoder
                var decoder = await BitmapDecoder.CreateAsync(fileStream);

                // create the output file for the thumbnail
                var thumbFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                    string.Format("thumbnail{0}", file.FileType),
                    CreationCollisionOption.GenerateUniqueName);

                // create a stream for the output file
                using (var outputStream = await thumbFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    // create an encoder from the existing decoder and set the scaled height
                    // and width 
                    var encoder = await BitmapEncoder.CreateForTranscodingAsync(
                        outputStream,
                        decoder);
                    encoder.BitmapTransform.ScaledHeight = 100;
                    encoder.BitmapTransform.ScaledWidth = 100;
                    await encoder.FlushAsync();
                }

                // create the URL
                var storageUrl = string.Format(URI_LOCAL, thumbFile.Name);

                // return it
                return new Uri(storageUrl, UriKind.Absolute);
            }
        }
开发者ID:griffinfujioka,项目名称:Archive,代码行数:32,代码来源:ThumbnailMaker.cs

示例2: ReadStorageFileToByteBuffer

        private async static Task<byte[]> ReadStorageFileToByteBuffer(IStorageFile storageFile)
        {
            IRandomAccessStream accessStream = await storageFile.OpenReadAsync();
            byte[] content = null;

            using (Stream stream = accessStream.AsStreamForRead((int)accessStream.Size))
            {
                content = new byte[stream.Length];
                await stream.ReadAsync(content, 0, (int)stream.Length);
            }

            return content;
        }
开发者ID:mqmanpsy,项目名称:MetroLog,代码行数:13,代码来源:Wp8FileTarget.cs

示例3: CopyFileIntoIsoStore

 private static async Task CopyFileIntoIsoStore(IStorageFile sourceFile)
 {
     using (var s = await sourceFile.OpenReadAsync())
     using (var dr = new DataReader(s))
     using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
     using (var targetFile = isoStore.CreateFile(sourceFile.Name))
     {
         var data = new byte[s.Size];
         await dr.LoadAsync((uint)s.Size);
         dr.ReadBytes(data);
         targetFile.Write(data, 0, data.Length);
     }
 }
开发者ID:pmacn,项目名称:VoiceRecorder.WP8,代码行数:13,代码来源:ExportRecordingViewModel.cs

示例4: ReadTextAsync

    internal async static Task<string> ReadTextAsync(IStorageFile storageFile)
    {
      string text;

      IRandomAccessStream accessStream = await storageFile.OpenReadAsync();

      using (Stream stream = accessStream.AsStreamForRead((int)accessStream.Size))
      {
        byte[] content = new byte[stream.Length];
        await stream.ReadAsync(content, 0, (int)stream.Length);

        text = Encoding.UTF8.GetString(content, 0, content.Length);
      }

      return text;
    }
开发者ID:KateGridina,项目名称:Q42.WinRT,代码行数:16,代码来源:FileIO.cs

示例5: ResizeAndSaveAs

        internal static async Task ResizeAndSaveAs(IStorageFile source, IStorageFile destination, 
            int targetDimension)
        {
            // open the file...
            using(var sourceStream = await source.OpenReadAsync())
            {
                // step one, get a decoder...
                var decoder = await BitmapDecoder.CreateAsync(sourceStream);

                // step two, create somewhere to put it...
                using(var destinationStream = await destination.OpenAsync(FileAccessMode.ReadWrite))
                {
                    // step three, create an encoder...
                    var encoder = await BitmapEncoder.CreateForTranscodingAsync(destinationStream, decoder);

                    // how big is it?
                    uint width = decoder.PixelWidth;
                    uint height = decoder.PixelHeight;
                    decimal ratio = (decimal)width / (decimal)height;

                    // orientation?
                    bool portrait = width < height;

                    // step four, configure it...
                    if (portrait)
                    {
                        encoder.BitmapTransform.ScaledHeight = (uint)targetDimension;
                        encoder.BitmapTransform.ScaledWidth = (uint)((decimal)targetDimension * ratio);
                    }
                    else
                    {
                        encoder.BitmapTransform.ScaledWidth = (uint)targetDimension;
                        encoder.BitmapTransform.ScaledHeight = (uint)((decimal)targetDimension / ratio);
                    }

                    // step five, write it...
                    await encoder.FlushAsync();
                }
            }
        }
开发者ID:mbrit,项目名称:ProgrammingMetroStyle,代码行数:40,代码来源:ImageHelper.cs

示例6: DoCreateEntryFromFile

        private static async Task<ZipArchiveEntry> DoCreateEntryFromFile(ZipArchive destination, IStorageFile sourceFile, string entryName, CompressionLevel? compressionLevel)
        {
            if (destination == null)
                throw new ArgumentNullException("destination");
            if (sourceFile == null)
                throw new ArgumentNullException("sourceFile");
            if (entryName == null)
                throw new ArgumentNullException("entryName");
            using (Stream stream = (await sourceFile.OpenReadAsync()).AsStream())
            {
                ZipArchiveEntry zipArchiveEntry = compressionLevel.HasValue ? destination.CreateEntry(entryName, compressionLevel.Value) : destination.CreateEntry(entryName);

                var props = await sourceFile.GetBasicPropertiesAsync();

                DateTime dateTime = props.DateModified.UtcDateTime;
                if (dateTime.Year < 1980 || dateTime.Year > 2107)
                    dateTime = new DateTime(1980, 1, 1, 0, 0, 0);
                zipArchiveEntry.LastWriteTime = (DateTimeOffset)dateTime;
                using (Stream destination1 = zipArchiveEntry.Open())
                {
                    await stream.CopyToAsync(destination1);
                }
                return zipArchiveEntry;
            }
        }
开发者ID:mqmanpsy,项目名称:MetroLog,代码行数:25,代码来源:ZipFile.cs

示例7: POST

		//http://www.techcoil.com/blog/sending-a-file-and-some-form-data-via-http-post-in-c/
		public static async Task<WebResult> POST(string url, IStorageFile file, Dictionary<string, string> additionalContent, string token = null)
		{
			string boundaryString = "----DiscordUWP8Boundary" + new Random().Next(0, 999);

			HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
			request.Method = "POST";
			request.ContentType = "multipart/form-data; boundary=" + boundaryString;

			request.Headers["Connection"] = "Keep-Alive";
			if (token != null) request.Headers["Authorization"] = token;

			MemoryStream postDataStream = new MemoryStream();
			StreamWriter postDataWriter = new StreamWriter(postDataStream);

			foreach(KeyValuePair<string, string> content in additionalContent)
			{
				postDataWriter.Write("\r\n--" + boundaryString + "\r\n");
				postDataWriter.Write("Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}", content.Key, content.Value);
			}

			postDataWriter.Write("\r\n--" + boundaryString + "\r\n");
			postDataWriter.Write("Content-Disposition: form-data;" + "name=\"{0}\";" + "filename=\"{1}\"" + "\r\nContent-Type: {2}\r\n\r\n", "file", Path.GetFileName(file.Path), Path.GetExtension(file.Path));
			postDataWriter.Flush();

			// Read the file

			var stream = await file.OpenReadAsync();

			byte[] buffer = new byte[1024];

			using (var ss = stream.AsStreamForRead(1024))
			{
				int bytesRead = 0;
				while ((bytesRead = await ss.ReadAsync(buffer, 0, buffer.Length)) != 0)
				{
					postDataStream.Write(buffer, 0, bytesRead);
				}
			}

			postDataWriter.Write("\r\n--" + boundaryString + "--\r\n");
			postDataWriter.Flush();

			// Dump the post data from the memory stream to the request stream
			using (Stream s = await request.GetRequestStreamAsync())
			{
				postDataStream.WriteTo(s);
			}

			postDataWriter.Dispose();
			postDataStream.Dispose();

			try
			{
				using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
				{
					using (StreamReader reader = new StreamReader(CheckForCompression(response), Encoding.UTF8))
					{
						return new WebResult { Data = reader.ReadToEnd(), Status = response.StatusCode };
					}
				}
			}
			catch (WebException e)
			{
				using (HttpWebResponse response = (HttpWebResponse)e.Response)
				{
					using (StreamReader reader = new StreamReader(CheckForCompression(response), Encoding.UTF8))
					{
						return new WebResult { Data = reader.ReadToEnd(), Status = response.StatusCode };
					}
				}
			}
		}
开发者ID:romgerman,项目名称:DiscordUWP8,代码行数:73,代码来源:Web.cs

示例8: AddKeyFile

        public async Task AddKeyFile(IStorageFile file)
        {
            KeyfileName = file.Name;
            using (var input = await file.OpenReadAsync())
                await _password.AddKeyFile(input);

            NotifyOfPropertyChange(() => CanOpenDatabase);
            NotifyOfPropertyChange(() => CanClearKeyfile);
            NotifyOfPropertyChange(() => KeyfileGroupVisibility);
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:10,代码来源:PasswordViewModel.cs


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