Wednesday, August 29, 2012

Loading an Image in Local HTML

Loading an Image in Local HTML

In my Windows Phone 7 Application I am loading a HTML file on a web browser.The HTML file contains Photo in which the Image have to be loaded from Isolated storage (already stored).Can any one plz guide me(Is there any sample or tutorial present online).

Answers & Comments...

Answer: 1

Have a look at this, it is a snippet from the above pasted link

Private ImageSource getImageFromIsolatedStorage(string imageName) {     BitmapImage bimg = new BitmapImage();      using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())     {         using (IsolatedStorageFileStream stream = iso.OpenFile(imageName, FileMode.Open, FileAccess.Read))         {             bimg.SetSource(stream);         }     }     return bimg; } 
by : Johanhttp://stackoverflow.com/users/1471542

Answer: 2

You could always convert the image to base64 and include the base64 as text in the document.

An example I quickly created can be viewed here: http://jsfiddle.net/NLxdB/

After you have your image as base64 you can add it in html like following: <img src="data:image/png;base64, BASE64IMAGE" /> where you replace BASE64IMAGE with you base64 string.

(EDIT: data:image/png needs to be replaced with jpg/gif or what ever the image type is.)

To get a base64 of your image you could use the following code:

string base64 = null; using (var iso = IsolatedStorageFile.GetUserStoreForApplication()) using (var isf = iso.OpenFile(imageName, FileMode.Open, FileAccess.Read)) using (var ms = new MemoryStream()) {     isf.CopyTo(ms);     base64 = Convert.ToBase64String(ms.ToArray()); } 
by : SynerCoderhttp://stackoverflow.com/users/637425




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog