[英]Convert an IBuffer to a byte array in Windows Phone 8.1, how?
I'm writing an application for Windows Phone 8.1. 我正在为Windows Phone 8.1编写应用程序。
I need to save an UIElement as an image file (I'd prefer JPG or PNG). 我需要将UIElement保存为图像文件(我更喜欢JPG或PNG)。 I'm using RenderTargetBitmap class to do this.
我正在使用RenderTargetBitmap类来执行此操作。 After calling the method RenderAsync on my UIElement I create an IBuffer that contains the result of the method GetPixelsAsync() of my RenderTargetBitmap.
在我的UIElement上调用RenderAsync方法之后,我创建了一个IBuffer,它包含了RenderTargetBitmap方法GetPixelsAsync()的结果。
Now I need to call the method ToArray() to convert my IBuffer in a byte array to save my image using something like BitmapEncoder, but it seems that on Windows Phone 8.1 there isn't any ToArray() method for IBuffer, while on Windows 8.1 is present. 现在我需要调用方法ToArray()来转换我的IBuffer在一个字节数组中使用像BitmapEncoder这样的东西来保存我的图像,但似乎在Windows Phone 8.1上没有任何用于IBuffer的ToArray()方法,而在Windows上8.1存在。
How can I solve this issue? 我该如何解决这个问题?
This is available on Windows Phone 8.1, but it not available on WP 8.0. 这在Windows Phone 8.1上可用,但在WP 8.0上不可用。 (see MSDN link )
(见MSDN链接 )
You need to make sure that you include the appropriate namespace however so it is found by the compiler: 您需要确保包含适当的命名空间,因此编译器可以找到它:
using System.Runtime.InteropServices.WindowsRuntime
I just don't want to create new question so decide to expand this one. 我只是不想创建新问题所以决定扩展这个问题。 It will be full answer for both platforms WP8 and Windows store app
它将是WP8和Windows应用程序平台的完整答案
Maybe you know how to convert IBuffer to byte[] in Windows Store App where we can't use this namespace: System.Runtime.InteropServices.WindowsRuntime 也许您知道如何在我们无法使用此命名空间的Windows应用商店应用中将IBuffer转换为byte []:System.Runtime.InteropServices.WindowsRuntime
Regards, Marcin 此致,Marcin
Proposal solution: I use code from this post: https://stackoverflow.com/a/21490534/3139083 提案解决方案:我使用此帖子中的代码: https : //stackoverflow.com/a/21490534/3139083
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.