
<phone:PhoneApplicationPage x:Class="solution.FullScreenVIEwer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/Expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" FontFamily="{StaticResource PhoneFontFamilynormal}" FontSize="{StaticResource PhoneFontSizenormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrIEntations="PortraitOrLandscape" OrIEntation="Portrait" mc:Ignorable="d" shell:SystemTray.IsVisible="True"> <Image name="img" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"Stretch="Uniform"/> </phone:PhoneApplicationPage> 这只是一个更大项目的一部分.我想在点击它之后实现te feture以全屏打开图像,所以我用另一个图像制作了另一个页面.我正在使用以下代码从C#加载图像:
protected overrIDe voID OnNavigatedTo(NavigationEventArgs e) { string context = this.NavigationContext.queryString["context"]; img.source = new BitmAPImage(new Uri(context,UriKind.relativeOrabsolute)); base.OnNavigatedTo(e); } 现在我想添加一个缩放图片的选项,但我不知道如何.我也尝试了谷歌,但我发现的唯一一件事是在ScroolVIEwer中使用ZoomMode,这对我不起作用(它说成员ZoomMode无法识别).
还有其他解决方案可以放大吗?
解决方法 您可以使用其中包含另一个GrID的GrID,而不是您正在使用的图像.在第二个网格上,使用GrID.Rendertransform通过缩放变换调整其内容(网格中的图像).您可以使用ManipulationDelta事件来跟踪放大或缩小的时间.
使用它你可以缩放图片,但这不是很好,因为你只关注图像的左上角.为避免这种情况,您可以通过在图像渲染转换标记中添加转换变换来启用用户滚动图像.您可以在下面的代码中看到如何执行此 *** 作:
<GrID x:name="LayoutRoot" ManipulationDelta="LayoutRoot_ManipulationDelta"> <GrID x:name="ContentPanel"> <GrID x:name="imageGrID"> <GrID.Rendertransform> <Scaletransform x:name="Imagetransform" /> </GrID.Rendertransform> <Image x:name="img" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Stretch="Uniform" Source="/Resources/logo/CTK .png" ManipulationDelta="img_ManipulationDelta" ManipulationCompleted="img_ManipulationCompleted"> <Image.Rendertransform> <Translatetransform x:name="Pantransform"/> </Image.Rendertransform> <Image.Resources> <Storyboard x:name="Pan"> <DoubleAnimation x:name="PanAnimation" Storyboard.Targetname="Pantransform" Storyboard.TargetProperty="X" Duration="0:0:1"> <DoubleAnimation.EasingFunction> <CircleEase EasingMode="EaSEOut" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard> </Image.Resources> </Image> </GrID> </GrID></GrID>
这是缩放和翻译的C#代码:
private voID LayoutRoot_ManipulationDelta(object sender,System.windows.input.ManipulationDeltaEventArgs e) { if (e.DeltaManipulation.Scale.X > 0.0 && e.DeltaManipulation.Scale.Y > 0.0) { // Scale in the X direction double tmp = Imagetransform.ScaleX * ((e.DeltaManipulation.Scale.X + e.DeltaManipulation.Scale.Y) / 2); if (tmp < 1.0) tmp = 1.0; else if (tmp > 4.0) tmp = 4.0; Imagetransform.ScaleX = tmp; // Scale in the Y direction tmp = Imagetransform.ScaleY * ((e.DeltaManipulation.Scale.X + e.DeltaManipulation.Scale.Y) / 2); if (tmp < 1.0) tmp = 1.0; else if (tmp > 4.0) tmp = 4.0; Imagetransform.ScaleY = tmp; } } private voID img_ManipulationDelta(object sender,System.windows.input.ManipulationDeltaEventArgs e) { // First make sure we're translating and not scaling (one finger vs. two) if (e.DeltaManipulation.Scale.X == 0.0 && e.DeltaManipulation.Scale.Y == 0.0) { Image photo = sender as Image; Translatetransform transform = photo.Rendertransform as Translatetransform; // Compute the new X component of the transform double x = transform.X + e.DeltaManipulation.Translation.X; double y = transform.Y + e.DeltaManipulation.Translation.Y; // Apply the computed value to the transform transform.X = x; transform.Y = y; } } private voID img_ManipulationCompleted(object sender,System.windows.input.ManipulationCompletedEventArgs e) { if (e.IsInertial) { Image photo = sender as Image; // Compute the inertial distance to travel double dx = e.FinalVeLocitIEs.linearVeLocity.X / 10.0; double dy = e.FinalVeLocitIEs.linearVeLocity.Y / 10.0; Translatetransform transform = photo.Rendertransform as Translatetransform; double x = transform.X + dx; double y = transform.Y + dy; // Apply the computed value to the animation PanAnimation.To = x; // Trigger the animation Pan.Begin(); } } 总结 以上是内存溢出为你收集整理的c# – 在WP8.1中缩放图像全部内容,希望文章能够帮你解决c# – 在WP8.1中缩放图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)