如何在智能设备应用程序(C#)中将object[]转换为图像?

发布于 2024-08-23 18:14:35 字数 384 浏览 7 评论 0原文

我正在用 C# 开发智能设备应用程序。我正在调用网络服务。 Web 服务方法返回 Google 地图。该方法的返回类型是object[]。对象[]包含字节格式的图像。 Google 地图图像的肥皂响应是 xsi:type="xs:base64Binary"。在对象中我没有得到字符串。在对象中我得到字节数组。 所以我在以下变量中捕获网络服务的响应。

对象[] GoogleMap;

调试后我可以看到在自动中我得到的结果如下。

名称: 价值: 谷歌地图{对象[1]} [0] {byte[23570]}

我需要在我的应用程序中显示实际图像。我需要执行什么类型的转换才能显示图像。请确保 .net 框架的所有核心功能不适用于 .net 紧凑框架。您能给我提供可以解决上述问题的代码或任何链接吗?

I am developing smart device application in C#. In that I am calling the web services. The web service method return Google map. The return type of the method is object []. The object [] contains the image in byte format. The soap response for Google Maps image is xsi:type="xs:base64Binary". In object I am not getting the string. In object I am getting the byte array.
So I am catching the response of web service in following variable.

object [] GoogleMap;

After debugging I can see that in auto I am getting the result as follows.

Name: Value:
GoogleMap {object[1]}
[0] {byte[23570]}

I need to display the actual image in my application. What type of casting I need to do to display the image.Please make sure that all the core functions of .net framework does not work with .net compact framework. Can you provide me the code or any link through which I can resolve the above issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2024-08-30 18:14:35

首先,您需要取出字节数组:

byte[] data = (byte[]) objects[0];

然后创建一个 < code>MemoryStream 围绕它:

MemoryStream stream = new MemoryStream(data);

现在从流创建一个 Bitmap

Bitmap bitmap = new Bitmap(stream);

请注意,您不应该关闭 MemoryStream > - 当您处理Image时,这将关闭流。

(编辑:从 Image.FromStream 更改为调用 Bitmap 构造函数,因为 Image.FromStream 似乎不在 CF 中。)

First you need to get the byte array out:

byte[] data = (byte[]) objects[0];

Then create a MemoryStream around it:

MemoryStream stream = new MemoryStream(data);

Now create a Bitmap from the stream:

Bitmap bitmap = new Bitmap(stream);

Note that you should not close the MemoryStream - when you dispose of the Image, that will close the stream.

(EDIT: Changed from Image.FromStream to calling the Bitmap constructor as Image.FromStream appears not to be in the CF.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文