2011-07-10 7 views
1

私は標準のCameraChooserTaskダンスをやっています。私のコールバックでは、キャプチャした写真の寸法を取得したいと思います。ストリームの画像の寸法を(レンダリングせずに)どのように取得するのですか?

私は以下のように、BitmapImageを使用してみましたが、BitmapImageは、レンダリングツリーの一部ではないので、私はそれが実際に(そのImageOpenedイベントは発生しません)任意のデコードを行うとは思いません。

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 ... 

答えて

2

ああ、このトリックは誰かにBitmapSourceを強制的に使用させることです。これをImageのソースとして割り当てることにより、PixelHeightPixelWidthのプロパティが設定されます。

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 ... 
関連する問題