【问题标题】:How to get Image height and width issue in windows phone 7如何在 windows phone 7 中获取图像高度和宽度问题
【发布时间】:2012-06-25 14:06:03
【问题描述】:

我正在尝试在 windows phone 中获取图像的高度和宽度...但是几乎没有语法错误

我该怎么做?

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

【问题讨论】:

  • 你的错误是什么,在哪一行?
  • 所有行中的错误。无法使用 ActualHegiht n ActualWidth 然后在括号中再次出现错误
  • 其中一个错误是 ActualWidth 和 ActualHeight 是双精度值。对局部变量使用 double 或将值转换为 int。提供有关 image1 的用法以及何时尝试执行您发布的代码的更多信息。

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


【解决方案1】:

要创建图像,

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

希望这能消除你的疑虑

【讨论】:

  • 是的,我的大部分疑虑都很清楚..但我仍然没有得到bmp.PixelHeight = (int)height; bmp.PixelWidth = (int)width;
  • 更新了我的答案,我在这里忘记了一件事 BitmapImage 的 PixelHeight 和 PixelWidth 属性是只读属性。如果您还有任何疑问,请告诉我
猜你喜欢
  • 2012-03-15
  • 1970-01-01
  • 2010-11-18
  • 1970-01-01
  • 1970-01-01
  • 2011-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多