代码改变世界

WP7备注(9)(CameraCaptureTask+PhotoChooserTask+PictureCollection)

2011-04-27 09:27  血糯米Otomii  阅读(340)  评论(0编辑  收藏  举报

CameraCaptureTask:

Show出一个框进行CameraCapture

CameraCaptureTask camera = new CameraCaptureTask();
camera.Completed += OnCameraCaptureTaskCompleted;
camera.Show();

void OnCameraCaptureTaskCompleted(object sender, PhotoResult args)
{
if (args.TaskResult == TaskResult.OK)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(args.ChosenPhoto);
img.Source = bmp;
}
}

PhotoChooserTask:

Show出一个框进行PhotoChooser

PhotoChooserTask photoChooser = new PhotoChooserTask();
photoChooser.Completed += OnPhotoChooserCompleted;
photoChooser.Show();
void OnPhotoChooserCompleted(object sender, PhotoResult args)
{
if (args.TaskResult == TaskResult.OK)
texture = Texture2D.FromStream(this.GraphicsDevice, args.ChosenPhoto);
}

PictureCollection:

仅获取为一个media图片集合

PictureCollection pictures = mediaLib.Pictures;
if (pictures.Count > 0)
{
int index = rand.Next(pictures.Count);
Picture pic = pictures[index];
BitmapImage bmp = new BitmapImage();
bmp.SetSource(pic.GetImage());
img.Source = bmp;
}