[RESOLVED] [2012] Windows Store Application: Image Source
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] [2012] Windows Store Application: Image Source

  1. #1
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    [RESOLVED] [2012] Windows Store Application: Image Source

    OK, this really sucks!

    I just want to display a picture from a dynamically created path.

    This is my code :
    Code:
        Private arrFolderNames() As String
        Private arrSubFolderNames() As String
        Private arrFileNames() As String
    
        Private Async Sub btSelect_Click(sender As Object, e As RoutedEventArgs) Handles btSelect.Click
    
    
            Dim RootFolder As StorageFolder = KnownFolders.PicturesLibrary
    
            Dim FolderList As IReadOnlyList(Of IStorageItem) = Await RootFolder.GetItemsAsync
    
            Dim Counter As Integer
    
            For Each folder In FolderList
    
                If TypeOf folder Is StorageFolder Then
                    lstFolders.Items.Add(folder.Name)
                    ReDim Preserve arrFolderNames(Counter)
                    arrFolderNames(Counter) = folder.Path
                    Counter += 1
    
                End If
            Next
    
    
    
        End Sub
    
        Private Async Sub lstFolders_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles lstFolders.SelectionChanged
            Dim SubFolder As StorageFolder = Await StorageFolder.GetFolderFromPathAsync(arrFolderNames(lstFolders.SelectedIndex))
    
            Dim SubFolderList As IReadOnlyList(Of IStorageItem) = Await SubFolder.GetItemsAsync
    
            Dim Counter As Integer
    
            For Each Folder In SubFolderList
    
                If TypeOf Folder Is StorageFolder Then
                    lstSubFolders.Items.Add(Folder.Name)
                    ReDim Preserve arrSubFolderNames(Counter)
                    arrSubFolderNames(Counter) = Folder.Path
                    Counter += 1
                End If
            Next
        End Sub
    
        Private Async Sub lstSubFolders_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles lstSubFolders.SelectionChanged
            Dim SubFolder As StorageFolder = Await StorageFolder.GetFolderFromPathAsync(arrSubFolderNames(lstSubFolders.SelectedIndex))
    
            Dim SubFolderList As IReadOnlyList(Of IStorageItem) = Await SubFolder.GetItemsAsync
    
            Dim Counter As String
            For Each File In SubFolderList
    
                If TypeOf File Is StorageFile Then
                    lstFiles.Items.Add(File.Name)
                    ReDim Preserve arrFileNames(Counter)
                    arrFileNames(Counter) = File.Path
                    Counter += 1
                End If
            Next
        End Sub
    
        Private Sub lstFiles_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles lstFiles.SelectionChanged
    
            Dim TempImage As New BitmapImage()
            Dim strPicLoc As String = arrFileNames(lstFiles.SelectedIndex)
    
            TempImage.UriSource = New Uri(strPicLoc, UriKind.Absolute)
    
            imgWall.Stretch = Stretch.Fill
    
            imgWall.Source = TempImage
    
    
        End Sub
    As you can probably see, I continously build a file path. First, I store the main folder path, then the selected subfolder path, and finally the file name inside a particular sub folder.

    Now, I want to display the picture ( which is the selected file ) inside an Image control.

    I have set breakpoints and my URI is correct and by all sense it should show the picture - which it doesn't

    I searched everywhere and MSDN's help is so useless, I have literally tried each and every example on there to no avail!

    Is there some magic trick I should know?

    Hannes

  2. #2
    Join Date
    Apr 2012
    Posts
    29

    Re: [2012] Windows Store Application: Image Source

    Here, I posted a suggestion in the thread you have over @ VBForums.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: [2012] Windows Store Application: Image Source

    Thanx again for your interest

    OK, I fixed it. yay!

    My whole problem was that I never actually opened / read the contents of the file. So, I tried a whole different route. I did this :

    Code:
    Dim strPicLoc As String = arrFileNames(lstFiles.SelectedIndex)
    
    Dim File2 As StorageFile = Await StorageFile.GetFileFromPathAsync(strPicLoc)
    
    Dim src as New BitmapImage()
    
    src.SetSource(Await File2.OpenAsync.FileAccessMode.Read))
    
    imgWall.Source = src
    It is amazing what sleep can do.

    Hannes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center