[WindowsPhone] 隨貼即用 - 讀取相簿照片

2013-10-25

簡述 : 讀取手機內部相簿的相片,載入至Image物件

難度 : ★

範例敘述:  一顆按鈕,點擊後讀取手機內部相簿的相片,載入至Image物件

程式碼:


private void btnShareMedia_Click(object sender, RoutedEventArgs e)
{
 
    PhotoChooserTask pct = new PhotoChooserTask();
    pct.Completed += delegate(object pctSender, PhotoResult photoResult)
        {
            if (photoResult.TaskResult == TaskResult.OK)
            {
                var bitmap=new BitmapImage();
                bitmap.SetSource(photoResult.ChosenPhoto);
                Image物件.Source = bitmap;
            }
            else
            {
                MessageBox.Show("選取相片,未成功");
            }
        };
 
    pct.ShowCamera = true;
    pct.Show();
 
 
}


範例結果:
2013-10-25_190050

2013-10-25_190019

2013-10-25_190002

 

下載源碼:


當麻許的超技八 2014 | Donma Hsu Design.