簡體   English   中英

根據圖像的寬度和高度更改方向

[英]Change the orientation based on Image width and height

我所顯示的圖像很少,現在有一些圖像的寬度大於圖像的高度。

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

display the image in landscape mode, else display the image in portrait mode.

我已經搜索過,在這種情況下找不到任何可以幫助我的資源。

任何幫助,將不勝感激。

請不要說我在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;

試試這個,首先將復合變換添加到圖像

        <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度。

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

對於“隱藏代碼”,首先添加復合變換,然后將其設置為image

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

然后檢查圖像的高度寬度(希望您具有高度寬度),並根據高度寬度設置復合變換旋轉。 根據需要使用-90度或+90度。

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

要獲取圖片的寬度和高度,

double height = image1.ActualHeight;
double width = image1.ActualWidth;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM