本文整理汇总了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;
}
示例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();
}
示例3: UpdateImage
public void UpdateImage(IRandomAccessStream rass)
{
storage["Picture"] = new ParseFile("Picture.jpg", rass.AsStreamForRead());
this.RaisePropertyChanged("Picture");
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例8: Load
public LoadResult Load(IRandomAccessStream lineStream)
{
StartLoad(lineStream.AsStreamForRead());
return CreateResult();
}
示例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(" ");
}