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,演示。

  • 相关阅读:
    Markdown
    DNS解析流程
    maven 的各种命令
    ES6初体验——(1)let和const命令
    table相关的选择器 & children()与find()的区别 & 选择器eq(n)与nth-child(n)的差异
    Java MD5加密类
    POI操作Excel异常Cannot get a text value from a numeric cell
    MyEclipse+SSH开发环境配置
    JdbcTemplate详解
    Spring配置声明
  • 原文地址:https://www.cnblogs.com/virgil/p/2765968.html
Copyright © 2011-2022 走看看