简体   繁体   English

在Windows Phone 8.1中将IBuffer转换为字节数组,怎么样?

[英]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.

相关问题 在Windows Phone 8.1中将字节数组转换为图像的同步方法 - Synchronous way to convert byte array to image in Windows Phone 8.1 如何将字节数组转换为mp4文件文件MediaElment Windows Phone 8.1 - how to convert byte array to mp4 file file MediaElment windows phone 8.1 如何使用c#将图像转换为Windows Phone 8.1中的字节数组 - How to convert an image to byte array in windows phone 8.1 using c# 在Windows Phone 8.1中加载,显示,转换来自字节数组(数据库)的图像 - Load, show, convert image from byte array (database) in Windows Phone 8.1 将WriteableBitmap转换为Byte数组 - Windows Phone 8.1 - Silverlight - Converting WriteableBitmap to Byte array - Windows phone 8.1 - Silverlight 如何在Windows Phone 8中将像素字节数组转换为位图图像 - How to convert pixel byte array to bitmap image in windows phone 8 如何在Windows Phone 8.1上从数据库获取和显示图像作为字节数组 - How to get and display image as byte array from database on Windows Phone 8.1 如何使用解决方案中的图像制作字节数组。 (Windows Phone 8.1运行时) - How to make a byte array with an image from solution. (Windows Phone 8.1 runtime) 如何从UWP中的IBuffer或字节数组创建IDirect3DSurface - How to create a IDirect3DSurface from an IBuffer or byte array in UWP 转换/序列化字典 <string,string> 到Windows Phone 8中的字节数组byte [] - Convert/Serialize Dictionary<string,string> to byte array byte[] in windows phone 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM