问题描述
限时送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:关键词]
发布评论