WP7开发,从代码中改变Image控件的大小

发布于 2024-12-10 17:20:29 字数 1149 浏览 0 评论 0 原文

我正在开发图片查看器应用程序,我想为其添加新功能。 到目前为止,我已经在 XAML 中固定了 Image 控件的大小 Height="422" Width="444",但我想使用页面上所有可能的空间,它是 Width="447" Height="585"

<StackPanel Height="422" Width="444">
                            <Image Height="414" HorizontalAlignment="Center" Margin="9,6,0,0" Name="image2" Stretch="Uniform" VerticalAlignment="Center" Width="441" />
                        </StackPanel>

代码所以

var stream = new IsolatedStorageFileStream(path, FileMode.Open, _file);
            var image = new BitmapImage();
            image.SetSource(stream);
            stream.Close();
            if (image1 != null) image1.Source = image;

,我的问题是:

  1. 如何从后面的代码设置图像控件的大小,以便图片适合 Width="447" Height="585" 尺寸,我有纵向和横向的图片?
  2. 我需要纵向和横向方向支持,因此当方向更改时,我希望图片适合新尺寸 Width="585" Height="447",我该如何管理? (我想如果我能找到第一个问题的解决方案,那么我只需要正确的事件来处理这个问题)与此类似(http://stackoverflow.com/questions/6857142/handling-size-of-image-after- orientation-change-wp7),但我需要看一些代码才能理解。

请发布一些代码或教程链接,以防止“经典”对话框,其中一个人现在如何做并认为它很简单,而其他人现在知道它是如何工作的。

I am developing picture viewer application and I want to add new function to it.
Till this time, I have fixed size of Image control in the XAML
Height="422" Width="444",but I want to use all possible space on the page and it is Width="447" Height="585"

<StackPanel Height="422" Width="444">
                            <Image Height="414" HorizontalAlignment="Center" Margin="9,6,0,0" Name="image2" Stretch="Uniform" VerticalAlignment="Center" Width="441" />
                        </StackPanel>

Code behind

var stream = new IsolatedStorageFileStream(path, FileMode.Open, _file);
            var image = new BitmapImage();
            image.SetSource(stream);
            stream.Close();
            if (image1 != null) image1.Source = image;

So, my question is:

  1. How I can set the size of the Image control from the code behind, so the picture will fit to the Width="447" Height="585" size, I have both portrait and landscape oriented pictures?
  2. I need to have portrait and landscape orientation support, so when orientation is change I would like to picture fit to new size Width="585" Height="447", how I can manage that? (I guess if I will find solution to the first, than only think I need is right event to handle this) Similar to this (http://stackoverflow.com/questions/6857142/handling-size-of-image-after-orientation-change-wp7), but I need to see some code t in order to understand.

Please, post some code or link to the tutorial, in order to prevent “classic” dialog where one person now how to do it and think it is simple and other person have now idea how it work.

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

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

发布评论

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

评论(3

平生欢 2024-12-17 17:20:29

您可以通过图像控件的 Width 和 Height 属性直接更改其大小。

image2.Width = "447";
image2.Height = 585;

如果您想正确地适应图像控件中的图片,则可以使用属性 Stretch

image2.Stretch = Stretch.UnifromToFill;

来处理方向更改,处理页面的 OrientationChanged 事件并在其中进行图像操作

You can directly change the size of image control through it's Width and Height properties.

image2.Width = "447";
image2.Height = 585;

If you want to fit in your picture in the Image Control properly then you can use property Stretch

image2.Stretch = Stretch.UnifromToFill;

For handling the orientation change handle the OrientationChanged event of your page and do the image manipulation inside it

開玄 2024-12-17 17:20:29

试试这个,

当改变方向时会引发以下事件。

   private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
    {
        if (this.Orientation == PageOrientation.Portrait)
        {
            optionsup.VerticalOffset = 447;
            optionsup.HorizontalOffset = 585;
        }
        else
        {
            optionsup.VerticalOffset = 585;
            optionsup.HorizontalOffset = 447;
        }
    }

最初的方向是PortraitUp,然后

            optionsup.VerticalOffset = 447;
            optionsup.HorizontalOffset = 585;

我的英语很差,如果有任何错误不介意。

Try this one,

when change the orientation then the following event is reaised.

   private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
    {
        if (this.Orientation == PageOrientation.Portrait)
        {
            optionsup.VerticalOffset = 447;
            optionsup.HorizontalOffset = 585;
        }
        else
        {
            optionsup.VerticalOffset = 585;
            optionsup.HorizontalOffset = 447;
        }
    }

initially orientation is PortraitUp then

            optionsup.VerticalOffset = 447;
            optionsup.HorizontalOffset = 585;

I poor in english, if any mistakes dont mind.

狼性发作 2024-12-17 17:20:29

谢谢你们的回答,我是这样做的:我制作了 Name="image1" Stretch="UniformToFill"/ > 因此,Silverlight 将为我完成所有工作。

Thanks for your answers guys, I did it this way: I have made <Image Height="Auto" Width="Auto" and Name="image1" Stretch="UniformToFill"/> So, the Silverlight will do all job for me.

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