首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从StorageFile获取IRandomAccessStream

如何从StorageFile获取IRandomAccessStream
EN

Stack Overflow用户
提问于 2017-12-09 12:40:08
回答 1查看 1.1K关注 0票数 2

首先我宣布

代码语言:javascript
复制
private MediaCapture _mediaCapture;
StorageFile capturedPhoto;
IRandomAccessStream imageStream;

第二,我捕捉到了

代码语言:javascript
复制
var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

var capturedPhoto = await lowLagCapture.CaptureAsync();


await lowLagCapture.FinishAsync();

第三,我正在设置图像源:

代码语言:javascript
复制
var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;
SoftwareBitmap softwareBitmapBGRB = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
await bitmapSource.SetBitmapAsync(softwareBitmapBGRB);

image.Source = bitmapSource;

如何获取imageStream?我在xaml中使用了CaptureElement工具。

EN

回答 1

Stack Overflow用户

发布于 2017-12-10 23:45:08

这很简单,问题是你想用这个IRandomAccessStreem做什么。下面是我认为你需要的一些代码:

代码语言:javascript
复制
public void HandleImageFileOperations(StorageFile file)
{
    if (file != null)
    {
         //converts the StorageFile to IRandomAccessStream
         var stream = await file.OpenAsync(FileAccessMode.Read);
         //creates the stream to an Image just in-case you want to show it
         var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
         image.SetSource(stream);

         //creates the image into byte array just in-case you need it to store the image
         byte[] bitmapImageBytes = null;
         var reader = new Windows.Storage.Streams.DataReader(stream.GetInputStreamAt(0));
         bitmapImageBytes = new byte[stream.Size];
         await reader.LoadAsync((uint)stream.Size);
         reader.ReadBytes(bitmapImageBytes);
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47725372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档