Windows phone手机开发之图片选择器,照相机功能,计时器,加速度,图片路径问题,页面间传值,随机产生数字

21 篇文章 0 订阅
14 篇文章 0 订阅


 

  //随机9个不同的数
 int[] u=new u[9];
     private void suijishiyan() {
            Random rand = new Random();
          for (int i = 0; i < 9; i++)
            {
                u[i] = rand.Next(1,15);
                for (int l = 0; l < u.Length; l++)
                {
                 
                    if (i == l) {
                   
                   
                    }
                    else if(i!=l)
                    {
                        if (u[i] == u[l])
                        {

                            u[i] = rand.Next(1,15);
                            l = -1;
                     
                            continue;
                        }

                   
                    }
                }
               
            }
         
       
        }

 

WP7
去除数组中重复的值,只保存一个值
          string[] xx1 = name.Split('|');
             int chongfupd = 0;
             string jiajia = "";
             for (int i = 0; i < xx1.Length; i++)
             {
             
                 chongfupd = 0;
                 for (int l = i; l < xx1.Length; l++)
                 {
                     if (xx1[l] == xx1[i])
                     {
                         chongfupd++;
                     }
                 }
                 if (chongfupd > 1)
                 {
                    
                 }
                 else {
                 jiajia =jiajia+ xx1[i] + "|";//最后结果
                 }

             }

 


传值
 NavigationService.Navigate(new Uri("/页面导航/Page2.xaml?name=yzk&age=18",UriKind.Relative));
接值
  protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string name = NavigationContext.QueryString["name"];
            int age = Convert.ToInt32(NavigationContext.QueryString["age"]);//QueryString中取出的值是String类型
            PageTitle.Text = name + age;
        }


图片路径问题
img1.Source =new BitmapImage(new Uri("images/3.jpg", UriKind.Relative));

加速度
Accelerometer acc=new Accelerometer();
acc.ReadingChanged+=.....;
acc.Start();

void ...()
{
//ReaddingChanged不是在ui线程触法的
Dispatcher.BeginInvoke<()=>{
textBlock1.Text=""+e.X+e.Y+e.Z;
}

}

 


计时器
 private void button1_Click(object sender, RoutedEventArgs e)
        {
              DispatcherTimer timer1 = new DispatcherTimer();
             timer1.Interval = TimeSpan.FromMilliseconds(1000);//间隔时间
             timer1.Tick += new EventHandler(timer1_Tick);
             timer1.Start();
}
 void timer1_Tick(object sender, EventArgs e)
        {
           // stw.Angle += 10;
         
        }

 


照相机功能

 private void button1_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureTask cccc = new CameraCaptureTask();
            cccc.Completed += new EventHandler<PhotoResult>(cccc_Completed);
            cccc.Show();
        }

        void cccc_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
            BitmapImage img=new BitmapImage();
                img.SetSource(e.ChosenPhoto);
                img1.Source = img;
           
            }
        }

图片选择器
private void button1_Click(object sender, RoutedEventArgs e)
        {
            PhotoChooserTask pacTack = new PhotoChooserTask();//
            pacTack.Completed += new EventHandler<PhotoResult>(pacTack_Completed);
            pacTack.ShowCamera = true;//启用照相功能,即没有想要的图片时可以选择拍摄
            pacTack.Show();

        }

        void pacTack_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                BitmapImage img = new BitmapImage();
                img.SetSource(e.ChosenPhoto);
                image1.Source = img;
                }
        }


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值