且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

转换的ImageSource到Base64String - WP8

更新时间:2023-11-14 19:39:28

您可以得到 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);