我已經成功創建了我的第一個iot項目,並且可以獲取圖像以加載按下我的Raspberry Pi2上的按鈕。如何在Pi上顯示來自USB的隨機圖像
我試圖把一些代碼從一組圖像中組合出來,但是我有一些區域會掉下來。
1)我不知道如何從郫縣
2)我似乎無法從文件加載圖像,只能從嵌入的資源來掃描USB棒。
3)我似乎無法解決如何關閉應用程序,我會認爲App.exit
會這樣做,但似乎沒有。
基本上我只是在玩耍,我認爲一個好的學習項目是創建一個隨機顯示USB棒圖像的數碼相框,它對我來說一點都不好。
如果我可以讓它在按鈕上工作,我應該可以放入定時器並且可以很容易地運行它。
這裏是我的代碼,你可以從我註釋掉的部分看看我曾嘗試:
' The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
''' <summary>
''' An empty page that can be used on its own or navigated to within a Frame.
''' </summary>
Public NotInheritable Class MainPage
Inherits Page
Dim random As Random = New Random()
Private Sub ClickMe_Click(sender As Object, e As RoutedEventArgs)
'Dim DirectoryPath As String = "F:/VB.Net files/Images/"
'Dim finfo As FileInfo = New FileInfo(GetRandomImageFilePath(DirectoryPath))
'Dim filename As String = finfo.Name.Replace(finfo.Extension, "")
'BBPLogo.Source = New BitmapImage(New Uri("file:///" & finfo.FullName, UriKind.Relative))
BBPLogo.Source = New BitmapImage(New Uri("ms-appx:///Assets/Bowral-Bricks.png", UriKind.Absolute))
End Sub
Private Sub ExitButton_Click(sender As Object, e As RoutedEventArgs) Handles ExitButton.Click
End Sub
Public Function GetRandomImageFilePath(ByVal folderPath As String) As String
Dim files() As String = Directory.GetFiles(folderPath, "*.png")
Return files(random.Next(0, files.Length))
End Function
End Class
不知道,如果你需要它,但這裏是XAML
<Page
x:Class="PiTest01.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PiTest01"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Height="480" Width="800">
<Grid>
<Grid.Background>
<ImageBrush Stretch="Fill"/>
</Grid.Background>
<Image x:Name="BBPLogo" HorizontalAlignment="Left" Height="480" VerticalAlignment="Top" Width="800" RenderTransformOrigin="1.163,0.596" Stretch="UniformToFill"/>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="78,18,436,164" Height="178">
<Button x:Name="ClickMe" Content="Click Me!" Margin="10" HorizontalAlignment="Center" Click="ClickMe_Click"/>
<Button x:Name="ExitButton" Content="Exit" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="126"/>
</StackPanel>
</Grid>
</Page>
如果你打算投票,至少有禮貌地說出爲什麼我可以修復它。它通過評論代碼的方式顯示了兩方面的研究成果,而且我非常清楚我正在嘗試做什麼。 –