根据图像宽度和高度更改方向

根据图像宽度和高度更改方向

本文介绍了根据图像宽度和高度更改方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示的图像很少,现在有些图像的图像宽度大于图像的高度。

I have few images thats being displayed, now there are some images where the width of the image is greater than the height of the image.

说: image.GetWidth()> image.GetHeight();

以横向模式显示图像,
else
以纵向模式显示图像。

我已搜索过,在这种情况下无法找到任何可以帮助我的资源。

I have searched,and could not find any resource that will help me in this case.

任何帮助都将不胜感激。

Any help would be appreciated.

请注意,我不是WP8。

Please not that i am on WP8.

编辑

Grid grid = new Grid();
grid.VerticalAlignment = VerticalAlignment.Center;
grid.HorizontalAlignment = HorizontalAlignment.Center;
grid.Height = height; //set height
grid.Width = width; //set width
grid.Background = new SolidColorBrush(Colors.White);
Image img = new Image();
img.VerticalAlignment = VerticalAlignment.Center;
img.HorizontalAlignment = HorizontalAlignment.Center;
img.Source = source;


推荐答案

试试这个,首先将复合变换添加到图像

Try this,First add composite transform to image

        <Image Name="image" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform" RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <CompositeTransform x:Name="compositeTransform"/>
            </Image.RenderTransform>
        </Image>

然后检查图像的高度宽度(希望你有高度宽度)并根据高度设置复合变换旋转宽度。根据您的要求使用-90度或+90度。

then check Height width(hope you have height width) of image and set composite transform rotation as per height width. Use -90 degree or +90 degree as per your requirement.

        image.Height = 300;
        image.Width = 400;
        if (image.Height > image.Width)
        {
            compositeTransform.Rotation = 0.0;
        }
        else
        {
            compositeTransform.Rotation = 90.00;
        }
        image.Source =(ImageSource) new ImageSourceConverter().ConvertFromString("2011-Chrysler-300-Model-09-1024x1280.jpg");

对于Code Behind,首先添加复合变换然后将其设置为图像

For Code Behind first add composite transform then set it to image

    CompositeTransform transform = new CompositeTransform();
    transform.CenterX = 0.5;
    transform.CenterY = 0.5;
    image.RenderTransform = transform;

然后检查图像的高度宽度(希望你有高度宽度)并根据高度设置复合变换旋转宽度。根据您的要求使用-90度或+90度。

Then check Height width(hope you have height width) of image and set composite transform rotation as per height width. Use -90 degree or +90 degree as per your requirement.

        image.Height = 300;
        image.Width = 400;
        if (image.Height > image.Width)
        {
            transform.Rotation = 0.0;
        }
        else
        {
            transform.Rotation = 90.00;
        }
        image.Source =(ImageSource) new ImageSourceConverter().ConvertFromString("2011-Chrysler-300-Model-09-1024x1280.jpg");

这篇关于根据图像宽度和高度更改方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:07