如何在Windows Phone 7中获取图像高度和宽度问题

时间:2012-06-24 11:07:29

标签: c# silverlight windows-phone-7 windows-phone-7.1

我试图在Windows手机中获取图像的高度和宽度...但语法错误很少

我该怎么做?

        int hight = image1.ActualHeight;
        int width = image1.ActualWidth;
        BitmapImage img = new BitmapImage(image1.Image);
        BitmapImage newImg = new BitmapImage(hight,width);

1 个答案:

答案 0 :(得分:3)

要创建图像,

<Image x:Name="image1" Source="myPicture.png" />

然后您可以在

后面的代码中访问它
double height = image1.ActualHeight;
double width = image1.ActualWidth;

并且没有BitmapImage类的构造函数,它接受您传递的参数。您可以使用以下任一方式创建新的BitmapImage

BitmapImage bmp = new BitmapImage(new Uri("myPicture.jpg", UriKind.RelativeOrAbsolute));

BitmapImage bmp = new BitmapImage();
bmp.UriSource = new Uri("myPicture.jpg", UriKind.RelativeOrAbsolute);

BitmapImage bitmapImage = image1.Source as BitmapImage;

希望这能清除你的怀疑

相关问题