Results 1 to 9 of 9

Thread: [RESOLVED] Windows Store Application: Image Source

  1. #1

    Thread Starter
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Resolved [RESOLVED] 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
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Windows Store Application: Image Source

    Is there some magic trick I should know?
    What about the one where you actually tell us what imgWall, which is evidently the most important variable in the whole thing, is? Is it a display control of some kind or merely, as it's name suggests, another image? If it's the latter then perhaps you could explain why you expect it to suddenly become visible?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Windows Store Application: Image Source

    Thanks for your sarcastic reply. I thought my explanation was quite thorough. But here goes:

    imgWall is an Image control - this control you find in your toolbox. You use an Image control to display images. I need to set the source of it. It is Visible by default, as the Visibility property ( in the properties window - the one where you set all your properties. A property is something that describes an object ) is set to Visible ( meaning it is visible ) the moment you create it ( by double clicking on it ).

    The lstFiles_SelectionChanged event ( this is an event for ListBoxes that happens when you select an item ) should display my picture - which is well, how can I make it simple, a PICTURE.

    Thanks again, for just adding onto my frustration...

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Windows Store Application: Image Source

    Quote Originally Posted by HanneSThEGreaT View Post
    Thanks for your sarcastic reply. I thought my explanation was quite thorough.
    Don't mind him Hannes , it takes a while to get used to his provocative posting style. He is actually quite a helpful and knowledgeable fellow. His thorns only look venomous but he's a teddy bear

    As for your problem....I've never actually used the BitmapImage class but from what I saw in the MSDN, you seem to have missed something. The sample code there places the setting of the UriSource property between a BeginInit and EndInit call which is missing from your code. Try that and see if it works.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Windows Store Application: Image Source

    Like this:-
    vbnet Code:
    1. '
    2.     Private Sub lstFiles_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles lstFiles.SelectionChanged
    3.  
    4.         Dim TempImage As New BitmapImage()
    5.         Dim strPicLoc As String = arrFileNames(lstFiles.SelectedIndex)
    6.  
    7.         TempImage.BeginInit() 'Added this
    8.         TempImage.UriSource = New Uri(strPicLoc, UriKind.Absolute)
    9.         TempImage.EndInit() 'Added this
    10.  
    11.         imgWall.Stretch = Stretch.Fill
    12.  
    13.         imgWall.Source = TempImage
    14.  
    15.  
    16.     End Sub
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6

    Thread Starter
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Windows Store Application: Image Source

    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

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: [RESOLVED] Windows Store Application: Image Source

    Ah ok cool
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: [RESOLVED] Windows Store Application: Image Source

    My whole problem was that I never actually opened / read the contents of the file.
    Uh-uh!

    His thorns only look venomous but he's a teddy bear
    Well, that's years of painstakingly putting together a convincing cover out the window then!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: [RESOLVED] Windows Store Application: Image Source

    Quote Originally Posted by dunfiddlin View Post
    Well, that's years of painstakingly putting together a convincing cover out the window then!
    That's why you need a cover for a cover, so you can avoid these entanglements
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

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



Click Here to Expand Forum to Full Width