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

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;
}
原文地址:https://www.cnblogs.com/otomii/p/2030021.html