如何帮助移动图像不超过屏幕上的限制

编程入门 行业动态 更新时间:2024-10-24 12:27:37
本文介绍了如何帮助移动图像不超过屏幕上的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我可以将这张图片向右或向左、向上、向下拖动它经过一个屏幕.我放大和缩小了.我想对此加以限制.使用 Windows Phone 8.1 应用程序.转换后,如果图像超出边界,则将图像带回来.您可以通过比较 TranslateX/TranslateY 的值和边界的宽度/高度来检测图像是否超出边界.边界是图像的父级(它是一个Grid?),需要调试代码来确定TranslateX和TranslateY的边界.

I can drag this pictures to right or left,up,down It passed over an screens.I had zoom in and out. I want limit about that. Using windows phone 8.1 app. After the transformation, brings the image back if it is out of the boundary. You can detect if the image is out of boundary by comparing the values of TranslateX/TranslateY and the width/height of the boundary. The boundary is the parent of the image (it is a Grid?), you need to debug the code to determine the boundary for TranslateX and TranslateY.

XAML

<Grid>
    <Grid Name="container">
        <Image Name="img_container" Source="/papers.co-mb00-baloon-fly-sea-wallpaper-1920x1080.jpg"
               ManipulationDelta="Image_ManipulationDelta"
               ManipulationMode="Scale,TranslateX,TranslateY"
               Stretch="Uniform"
                RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <CompositeTransform/>
            </Image.RenderTransform>
        </Image>
    </Grid>
</Grid>

C#

int mincale = 1;
private void Image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    Image img = sender as Image;
    CompositeTransform ct = img.RenderTransform as CompositeTransform;
    //zoom
    ct.ScaleX *= e.Delta.Scale;
    ct.ScaleY *= e.Delta.Scale;

    //checking

    if (ct.ScaleX < mincale)
        ct.ScaleX = mincale;
    if (ct.ScaleY < mincale)
        ct.ScaleY = mincale;

    //drag whitle zooming.

    ct.TranslateX += e.Delta.Translation.X;
    ct.TranslateY += e.Delta.Translation.Y;

    //checking drag not passed over a screen.that's fails.

    if (ct.TranslateX < 10 - img.ActualWidth * ct.ScaleX)
        ct.TranslateX = 10 - img.ActualWidth * ct.ScaleX;

    if (ct.TranslateX > container.ActualWidth - 10)
        ct.TranslateX = container.ActualWidth - 10;

    if (ct.TranslateY < 10 - img.ActualHeight * ct.ScaleY)
        ct.TranslateY = 10 - img.ActualHeight * ct.ScaleY;

    if (ct.TranslateY > container.ActualHeight - 10)
        ct.TranslateY = container.ActualHeight - 10;
}

推荐答案

可以根据设置的图片高宽查看分辨率.

you can check for which resolution is there , according to set Image height and width.

var scalfactor = App.Current.Host.Content.ScaleFactor;
switch (scalfactor)
            {
                case 150:
//write code for 720p or other screen Resolution

                  
                    break;
                case 160:
//write code for Wxga screen Resolution
          
                    break;
                case 100:
//write code for Wvga screen Resolution
              break;
                default:
                    throw new InvalidOperationException("Unknown resolution type");
            }

请参考此链接了解更多信息http://msdn.microsoft/en-us/library/windows/apps/jj206974%28v=vs.105%29.aspx

Plz refer this link for more info http://msdn.microsoft/en-us/library/windows/apps/jj206974%28v=vs.105%29.aspx

这篇关于如何帮助移动图像不超过屏幕上的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 13:54:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不超过   图像   屏幕上

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!