Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying a picture stored in Storage file in a metroapp
    primarykey
    data
    text
    <p>I would like to display the content of a picture stored in a StorageFile through a binding, but whatever I'm trying to do it doesn't seem to work.</p> <p>Here are the two solutions I have already tested :</p> <pre><code>string img =( await CompetencesFolder.GetFileAsync(FormatImageNameToFileName(imageName))).Path; </code></pre> <p>And then returning the path obtained (a full absolute path to the file) to the source Property through binding, and :</p> <pre><code> BitmapImage img = await LoadImage(await CompetencesFolder.GetFileAsync(FormatImageNameToFileName(imageName))); private static async Task&lt;BitmapImage&gt; LoadImage(StorageFile file) { BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); return bitmapImage; } </code></pre> <p>Returning the final bitmapImage later to my binded property.</p> <p>None of these methods works ..</p> <p>Do anyone have an idea?</p> <p><strong>EDIT : FIX</strong></p> <p>Here is the code that solved the problem :</p> <pre><code>BitmapImage img = new BitmapImage() { UriSource = new Uri( LOCAL_REPOSITORY.Path + "/Assets/gfx/cards/" + FormatImageNameToFileName(imageName) + ".jpg", UriKind.RelativeOrAbsolute) }; </code></pre> <p>I did a mix of the 2 samples above : I created my bitmapImage from the absolute URI of the picture (LOCAL_REPOSITORY contains a reference to the local storage : <code>ApplicationData.Current.LocalFolder</code>)</p> <p>I still can't figure why the 2 other ways failed : I usually bind my image directly to an Uri, a string or a BitmapImage, and it works ..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload