如何在 Silverlight 中获取图像的高度?

发布于 2024-08-26 07:03:35 字数 779 浏览 12 评论 0原文

我在 Silverlight 中有这段代码:

Image image = new Image();
BitmapImage bitmapImage= TheDatasourceManager.GetBitmapImage("blackPencil");
image.Source = bitmapImage;
image.Stretch = Stretch.None;
image.HorizontalAlignment = HorizontalAlignment.Left;
image.VerticalAlignment = VerticalAlignment.Top;
image.Margin = new Thickness(88, 88, 0, 0);
grid.Children.Add(image);

现在我想找出图像的高度

  • WPF 中,我可以使用 image.Source.Height 获取它,但这在 Silverlight 中不可用
  • bitmapImage.Height 也不存在,
  • 当我调试并检查图像对象,我最终得到 PixelHeight ,它具有准确的高度,但我似乎无法访问它,
  • 我找到 image.ActualHeight 但它是 0

如何获取图像的高度?

I have this code in Silverlight:

Image image = new Image();
BitmapImage bitmapImage= TheDatasourceManager.GetBitmapImage("blackPencil");
image.Source = bitmapImage;
image.Stretch = Stretch.None;
image.HorizontalAlignment = HorizontalAlignment.Left;
image.VerticalAlignment = VerticalAlignment.Top;
image.Margin = new Thickness(88, 88, 0, 0);
grid.Children.Add(image);

Now I want to find out the height of the image.

  • in WPF I can get it with image.Source.Height but this is not available in Silverlight
  • bitmapImage.Height doesn't exist either
  • when I debug and examine the image object, I eventually get to PixelHeight which has an accurate height, but I can't seem to access it
  • I find image.ActualHeight but it is 0.

How can I get the height of the image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许久 2024-09-02 07:03:35

我终于找到了,它只是bitmapImage.PixelHeight。因为我没有拉伸它,所以看起来效果很好。

I finally found it, it's just bitmapImage.PixelHeight. Since I'm not stretching it, seems to work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文