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


C# IRandomAccessStream.AsStreamForRead方法代码示例

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


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

示例1: UploadImgur

 public static async Task<ImgurEntity> UploadImgur(IRandomAccessStream fileStream)
 {
     try
     {
         var imageData = new byte[fileStream.Size];
         for (int i = 0; i < imageData.Length; i++)
         {
             imageData[i] = (byte)fileStream.AsStreamForRead().ReadByte();
         }
         var theAuthClient = new HttpClient();
         var request = new HttpRequestMessage(HttpMethod.Post, "https://api.imgur.com/3/image");
         request.Headers.Authorization = new AuthenticationHeaderValue("Client-ID", "e5c018ac1f4c157");
         var form = new MultipartFormDataContent();
         var t = new StreamContent(fileStream.AsStream());
         // TODO: See if this is the correct way to use imgur's v3 api. I can't see why we would still need to convert images to base64.
         string base64Img = Convert.ToBase64String(imageData);
         t.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
         form.Add(new StringContent(base64Img), @"image");
         form.Add(new StringContent("file"), "type");
         request.Content = form;
         HttpResponseMessage response = await theAuthClient.SendAsync(request);
         string responseString = await response.Content.ReadAsStringAsync();
         if (responseString == null) return null;
         var imgurEntity = JsonConvert.DeserializeObject<ImgurEntity>(responseString);
         return imgurEntity;
     }
     catch (WebException)
     {
     }
     catch (IOException)
     {
         return null;
     }
     return null;
 }
开发者ID:Ephemerial,项目名称:Awful-Forums-Reader,代码行数:35,代码来源:UploadManager.cs

示例2: GetThumbnailImage

        public async Task<IRandomAccessStream> GetThumbnailImage(IRandomAccessStream stream, int width, int height, bool smartCropping = true)
        {
            var response = await _client.GetThumbnailAsync(stream.AsStreamForRead(), width, height, smartCropping);

            var responseStream = new MemoryStream(response);
            return responseStream.AsRandomAccessStream();
        }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:7,代码来源:VisionApi.cs

示例3: UpdateImage

        public void UpdateImage(IRandomAccessStream rass)
        {

            storage["Picture"] = new ParseFile("Picture.jpg", rass.AsStreamForRead());

            this.RaisePropertyChanged("Picture");
        }
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:7,代码来源:UpdatesModel.cs

示例4: SaveToPicturesLibraryAsync

 /// <summary>
 /// Pictures Libraryへファイルを保存する
 /// 既存の同名ファイルが存在している場合はファイルを上書きする
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="stream">エンコード済みの画像ストリーム</param>
 /// <returns></returns>
 public static async Task<StorageFile> SaveToPicturesLibraryAsync(string fileName, IRandomAccessStream stream)
 {
     var library = KnownFolders.PicturesLibrary;
     var file = await library.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
     using (var writeStrm = await file.OpenStreamForWriteAsync())
     {
         var readStrm = stream.AsStreamForRead();
         readStrm.CopyTo(writeStrm);
     }
     return file;
 }
开发者ID:tanaka-takayoshi,项目名称:WriteableBitmapEffector,代码行数:18,代码来源:StorageExtensions.cs

示例5: GetPrevalentEmotion

        public async Task<string> GetPrevalentEmotion(IRandomAccessStream imageStream)
        {
            var result = await _client.RecognizeAsync(imageStream.AsStreamForRead());

            var emotionScores = typeof(Microsoft.ProjectOxford.Emotion.Contract.Scores).GetProperties()
                .Where(p => p.PropertyType == typeof(float))
                .Select(p => new { Name = p.Name, Score = (float)p.GetValue(result[0].Scores) });
                

            return emotionScores.OrderByDescending(s => s.Score).Select(s => s.Name).FirstOrDefault();
        }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:11,代码来源:EmotionApi.cs

示例6: SaveAsync

        public async override Task<bool> SaveAsync(string cacheKey, IRandomAccessStream cacheStream)
        {
            var fullFileName = Path.Combine(CacheDirectory, CacheFileNameGenerator.GenerateCacheName(cacheKey));
            var cacheSizeInBytes = cacheStream.AsStreamForRead().Length;

            while (CurrentCacheSizeInBytes + cacheSizeInBytes > _cacheLimitInBytes)
            {
                if (!await RemoveOldestCacheFile())
                {
                    break; // All cache deleted
                }
            }

            var wasFileSaved = await base.InternalSaveAsync(fullFileName, cacheStream);

            if (wasFileSaved)
            {
                _lastAccessTimeDictionary[Path.Combine(CacheDirectory, fullFileName)] = DateTimeHelper.CurrentTimeMillis();
                CurrentCacheSizeInBytes += cacheSizeInBytes; // Updating current cache size
            }

            return wasFileSaved;
        }
开发者ID:chenrensong,项目名称:ImageLib.UWP,代码行数:23,代码来源:LimitedStorageCache.cs

示例7: FixTextureContentType

    private async Task<IRandomAccessStream> FixTextureContentType(IRandomAccessStream modelStream)
    {
        XDocument xmldoc = XDocument.Load(modelStream.AsStreamForRead());

        var outputStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
        var writer = new Windows.Storage.Streams.DataWriter(outputStream);
        writer.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
        writer.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian;

        var text = xmldoc.ToString();

        var replacedText = text.Replace("contenttype=\"\"", "contenttype=\"image/png\"");
        writer.WriteString(replacedText);

        await writer.StoreAsync();
        await writer.FlushAsync();
        writer.DetachStream();
        return outputStream;
    }
开发者ID:AJ-COOL,项目名称:Windows-universal-samples,代码行数:19,代码来源:Print3D.cs

示例8: Load

        public LoadResult Load(IRandomAccessStream lineStream)
        {
            StartLoad(lineStream.AsStreamForRead());

            return CreateResult();
        }
开发者ID:rikkit,项目名称:ObjLoader,代码行数:6,代码来源:ObjLoader.cs

示例9: RecognizeTextAsync

        public async Task<string> RecognizeTextAsync(IRandomAccessStream stream, string language = "unk", bool detectOrientation = true)
        {
            var response = await _client.RecognizeTextAsync(stream.AsStreamForRead(), language, detectOrientation);

            return response.Regions.SelectMany(r => r.Lines).SelectMany(l => l.Words).Select(w => w.Text).StringJoin(" ");
        }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:6,代码来源:VisionApi.cs


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