zoukankan      html  css  js  c++  java
  • <metro>摄取相片

    首先,我们打开Vs2012,选择好Blank App模板。在MainPage.xaml中拉进Button和image两个空间。在Button控件中选择Click事件。经命名等后,代码如下:

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Button x:Name="Start" Content="Start" HorizontalAlignment="Left" Height="39" Margin="81,40,0,0" VerticalAlignment="Top" Width="88" Click="Start_Click"/>
            <Image x:Name="image" HorizontalAlignment="Left" Height="320" Margin="81,110,0,0" VerticalAlignment="Top" Width="434"/>
    
        </Grid>

    接着,在MainPage.xaml.cs中的Click事件里,填入一下代码就可以了:

    private async void Start_Click(object sender, RoutedEventArgs e)
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".gif");
                openPicker.FileTypeFilter.Add(".png");
    
                StorageFile file = await openPicker.PickSingleFileAsync();
    
                string fileToken;
                IStorageItemAccessList futureAccess = StorageApplicationPermissions.FutureAccessList;
                fileToken = futureAccess.Add(file);
    
                BitmapImage src = new BitmapImage();
                src.SetSource(await file.OpenAsync(FileAccessMode.Read));
                image.Source = src;
                AutomationProperties.SetName(image, file.Name);
                
            }

    然后,按F5,演示。

  • 相关阅读:
    C++笔记-智能指针 shared_ptr
    Linux笔记-性能调优工具perf
    git submodule 如何push代码
    性能测试工具gperftools使用
    Linux信号使用及自定义信号
    DNN在推荐系统中的应用参考资料
    vscode远程代码同步
    感知机模型到DNN模型
    c++笔记-libcurl多线程并发时的core【转载】
    go笔记-熔断器
  • 原文地址:https://www.cnblogs.com/virgil/p/2765968.html
Copyright © 2011-2022 走看看