有没有办法将Windows.UI.Xaml.Media.Imaging.BitmapSource对象转换为实现Microsoft.Graphics.Canvas.ICanvasImage的类的成员?界面本身只包含两个矩形获取方法。但是,我认为这还不够,因为我的最终目标是打电话
CanvasDrawingSession.DrawImage()
我必须想象的需要一种方法来获取位图像素。
答案 0 :(得分:1)
您无法直接从Windows.UI.Xaml.Media.Imaging。BitmapImage获取像素。但您可以使用WriteableBitmap而不是BitmapImage。然后,您可以通过其PixelBuffer属性获取像素数据。
之后,您可以使用CanvasBitmap.CreateFromBytes()
方法创建CanvasBitmap。然后使用此CanvasBitmap对象作为参数来调用CanvasDrawingSession.DrawImage()
方法。
答案 1 :(得分:1)
除了使用上面described by Xavier Xie的 PixelBuffer 之外,您还可以使用 SoftwareBitmap 创建 ICanvasImage 。如果你有一个流,那么你可以这样做:
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
CanvasDrawingSession.DrawImage(await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Rgba16, BitmapAlphaMode.Premultiplied));