如何在 Silverlight 中获取图像的高度?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于找到了,它只是bitmapImage.PixelHeight。因为我没有拉伸它,所以看起来效果很好。
I finally found it, it's just bitmapImage.PixelHeight. Since I'm not stretching it, seems to work fine.