2012-02-25 7 views
0

は、 画像の高さと幅の問題は、私はWindowsの携帯電話に新しいです7

は今だけ、スタックパネルで画像を表示しようとするサンプルをしています。

イメージを実際の高さと幅で表示したいとします。実際の高さと幅は0を返します。

実際に高さ360ピクセル、幅480ピクセルの画像です。

以下に私のコードを掲示しました。 Plsヘルプ。

ありがとうございました。

MaingPage.xaml

<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <StackPanel Name="imagePanel" ></StackPanel> 
</Grid> 

MainPage.xaml.cs

namespace ImageResizing 
{ 
public partial class MainPage : PhoneApplicationPage 
{ 
    Image myImage; 
    BitmapImage bit; 

    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 

     myImage = new Image(); 
     Uri uri = new Uri("Penguins.jpg", UriKind.Relative); 
     bit = new BitmapImage(uri); 
     myImage.Source = bit; 

     myImage.Width = myImage.ActualWidth; // Returns 0 
     myImage.Height = myImage.ActualHeight; // Returns 0 

     myImage.Width = bit.PixelWidth; // Also tried this. It returns 0 too 
     myImage.Height = bit.PixelHeight; // Also tried this. It returns 0 too 


     myImage.Stretch = Stretch.Fill; 
     imagePanel.Children.Add(myImage); 
    } 
    } 
} 

答えて

1

それらがmyImage.Source = bit;それ以前MYIMAGEへの呼び出しの後まで、ゼロではdoesnのちょうど空の画像であります内容はありません。

+0

uが言ったように私は、コードを再配置しました。しかし、高さと幅は0を返します。上記のコードをチェックしてください。 – Arun

+0

このサイト:http://www.i-programmer.info/programming/wpf-workings/520-bitmapimage-and-local-files-.html?start=1あなたが見ているものに関連する詳細をいくつか持っているかもしれません? –

0

ActualHeightとActualWidthは、レイアウトされレンダリングされた後の高さ/幅です。あなたがそれを得るとき、それはまだ描かれていません。

はただ、この部分を取り除くと、それが動作するはずです:

myImage.Width = myImage.ActualWidth; // Returns 0 
    myImage.Height = myImage.ActualHeight; // Returns 0 

    myImage.Width = bit.PixelWidth; // Also tried this. It returns 0 too 
    myImage.Height = bit.PixelHeight; // Also tried this. It returns 0 too 
関連する問題