zoukankan      html  css  js  c++  java
  • winPhone开启摄像头

     前台代码:

        <!--LayoutRoot 是包含所有页面内容的根网格-->     <Grid x:Name="LayoutRoot" Background="#eee">         <Grid.RowDefinitions>             <RowDefinition Height="Auto"/>             <RowDefinition Height="*"/>         </Grid.RowDefinitions>         <Grid x:Name="ContentPanel"  Margin="12,0,12,578" Grid.Row="1">
                <ListBox Height="768"  Margin="-12,0,-12,-578" Name="listBox1" Opacity="8" VerticalAlignment="Center">
                    <ListBox.ItemTemplate>                     <DataTemplate>                         <Image Width="500" Height="500" Margin="0,5,0,5"                                Source="{Binding}"></Image>                     </DataTemplate>                 </ListBox.ItemTemplate>             </ListBox>         </Grid>

        </Grid>
        <!--演示 ApplicationBar 用法的示例代码-->     <phone:PhoneApplicationPage.ApplicationBar>         <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">             <shell:ApplicationBarIconButton IconUri="appbar.feature.camera.rest.png" Text="按钮 1" Click="ApplicationBarIconButton_Click" />
            </shell:ApplicationBar>     </phone:PhoneApplicationPage.ApplicationBar>

    后台代码:

    private ObservableCollection<BitmapImage> bitmapImages = new ObservableCollection<BitmapImage>();

            public Page4()
            {
                InitializeComponent();
                LoadImg();
                listBox1.ItemsSource = bitmapImages;
            }


            private void LoadImg()
            {
                bitmapImages.Clear();
                IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
                try
                {
                    foreach (string file in isf.GetFileNames("baby"+"*.jpg"))//遍历所有jpg图片
                    {
                        BitmapImage bmpImg = new BitmapImage();
                        using (Stream stream = isf.OpenFile(file, FileMode.Open))
                        {
                            bmpImg.SetSource(stream);
                        }
                        bitmapImages.Add(bmpImg);
                    }
                }
                catch { }
            }


          
            void pcTask_Completed(object sender, PhotoResult e)
            {
                if (e.Error != null)
                {
                    CommonHelper.MsgBox("执行失败!");
                    return;
                }
                if (e.TaskResult == TaskResult.OK)
                {
                     //BitmapImage img = new BitmapImage();
                      //img.SetSource(e.ChosenPhoto);//用图片流初始化BitmapImage图片对象
                    string name = (string)IsolatedStorageSettings.ApplicationSettings["name"];
                     IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
                     string filename = "baby"+name+DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
                     using (e.ChosenPhoto)
                     {
                         Stream stream = isf.CreateFile(filename);
                         e.ChosenPhoto.CopyTo(stream);


                         BitmapImage bmpImg = new BitmapImage();
                         bmpImg.SetSource(stream);
                         bitmapImages.Add(bmpImg);
                     }
                }
                  
            }


            private void ApplicationBarIconButton_Click(object sender, EventArgs e)
            {
                PhotoChooserTask pcTask = new PhotoChooserTask();
                pcTask.ShowCamera = true;//显示拍照按钮,用户即可以选择图片,又可以拍照
                pcTask.PixelHeight = 100;//如果设定了PixelHeight和PixelWidth,则选择后的图片要求用户截取成合适的大小!
                pcTask.PixelWidth = 100;//可以用来实现上传QQ头像的功能。
                pcTask.Completed += new EventHandler<PhotoResult>(pcTask_Completed);
                pcTask.Show();


           
            }   
        }

  • 相关阅读:
    ZOJ 3818 Pretty Poem
    HDU 4597 Play Game
    HDU 4497 GCD and LCM
    CSU 1335 高桥和低桥
    UVA 10791 Minimum Sum LCM
    CSU 1119 Collecting Coins
    CSU 1120 病毒
    UVA 12169 Disgruntled Judge
    HDU 1301 Jungle Roads
    POJ 1258 Agri-Net
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/3109366.html
Copyright © 2011-2022 走看看