I'm doing the standard CameraChooserTask dance. In my callback, I'd like to get the dimensions of the captured photo.
I tried using Bit开发者_JAVA技巧mapImage
, as below, but since the BitmapImage
isn't part of the render tree, I don't think it actually does any decoding (its ImageOpened
event doesn't fire).
private void CameraCapture_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
{
// This code DOES NOT work:
// BitmapImage bi = new BitmapImage();
// bi.SetSource(stream);
// ... use bi.PixelHeight and bi.PixelWidth ...
Ah, the trick is to force someone to use the BitmapSource
. By assigning it as the source for an Image
, the PixelHeight
and PixelWidth
properties get set.
private void CameraCapture_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(stream);
Image image = new Image();
image.Source = bi;
// ... use bi.PixelHeight and bi.PixelWidth ...
精彩评论