转换的ImageSource到Base64String

编程入门 行业动态 更新时间:2024-10-26 04:24:52
本文介绍了转换的ImageSource到Base64String - WP8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

很努力WP8application,我在的位置资源\\图形\\几张图片我试图从这些文件夹中显示图像,但它不是选择的路径。

下面是我的code:

< IMG SRC = \\/资源;组件/显卡/+ ImageName).Append(\\),这是在我的字符串,我用我WebBrowserControl

WebBrowserControl.NavigateToString(HTML); //这里的HTML是具有所有的HTML code在它的字符串。

但其不显示图像。

所以我想在转换的ImageSource - 资源;组件/显卡/+ ImageName 来Base64String怎么办呢

我也看着很多的例子,但他们都不是WP8兼容。

解决方案

您可以得到 StreamInfo 通过使用这样的:

Application.GetResourceStream(新的URI(资源;组件/显卡/+ ImageName,System.UriKind.Relative));

然后,你可以读到这个流成字节数组。在此之后,使用 Convert.ToBase64String()来得到你想要的。尝试这个。也许你可以阅读MSDN文档,以获取如何使用流。

IMG VAR = Application.GetResourceStream(新的URI(资源;组件/显卡/+ ImageName,System.UriKind.Relative));VAR缓冲=新的字节[img.Stream.Length]img.Stream.Seek(0,SeekOrigin.Begin);img.Stream.Read(缓冲液,0,buffer.Length);变种的base64 = Convert.ToBase64String(缓冲液);

am working on WP8application, I have few images in location Resources\Graphics\ i am trying to display images from these folder, but its not picking the path.

Here is my code :

<img src=\"/Resources;component/Graphics/"+ImageName).Append("\" ") this is in my string which i am using in my WebBrowserControl.

WebBrowserControl.NavigateToString(html); // here html is a string which has all the html code in it.

But its not display the images.

So i want to convert the ImageSource --Resources;component/Graphics/"+ImageName to Base64String how to do it?

I have looked into many examples but none of them is compatible for WP8.

解决方案

You can get StreamInfo by using this:

Application.GetResourceStream(new Uri("Resources;component/Graphics/"+ImageName", System.UriKind.Relative));

Then you can read this stream into an byte array. After that, use Convert.ToBase64String() to get what you want. Try this. Maybe you can read the MSDN document to find how to use Stream.

var img = Application.GetResourceStream(new Uri("Resources;component/Graphics/"+ImageName", System.UriKind.Relative)); var buffer = new byte[img.Stream.Length]; img.Stream.Seek(0, SeekOrigin.Begin); img.Stream.Read(buffer, 0, buffer.Length); var base64 = Convert.ToBase64String(buffer);

更多推荐

转换的ImageSource到Base64String

本文发布于:2023-11-26 19:31:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634902.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ImageSource   Base64String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!