-
Aug 5th, 2013, 05:44 AM
#1
[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
-
Aug 5th, 2013, 03:06 PM
#2
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!
-
Aug 6th, 2013, 01:30 AM
#3
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...
-
Aug 6th, 2013, 01:58 AM
#4
Re: Windows Store Application: Image Source
Originally Posted by HanneSThEGreaT
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.
-
Aug 6th, 2013, 02:00 AM
#5
Re: Windows Store Application: Image Source
Like this:-
vbnet Code:
'
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.BeginInit() 'Added this
TempImage.UriSource = New Uri(strPicLoc, UriKind.Absolute)
TempImage.EndInit() 'Added this
imgWall.Stretch = Stretch.Fill
imgWall.Source = TempImage
End Sub
-
Aug 6th, 2013, 02:15 AM
#6
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
-
Aug 6th, 2013, 02:21 AM
#7
Re: [RESOLVED] Windows Store Application: Image Source
Ah ok cool
-
Aug 6th, 2013, 12:19 PM
#8
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!
-
Aug 6th, 2013, 12:33 PM
#9
Re: [RESOLVED] Windows Store Application: Image Source
Originally Posted by dunfiddlin
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|