原文:WPF3D图片轮播效果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37591671/article/details/68059169

1.   效果图:

(1)初始化:

(2)当点击该图片时,该图片放大

(3)当点击其他图片时,被点击图片移动到屏幕中央,再次点击放大。

2.   实现思路


3.具体实现

(1)第一步:获得图片路径

    String  myPath=” Pic”;声明文件夹的相对路径;

DirectoryInfodirectoryinfo = new DirectoryInfo(myPath);

FileInfo[] files =directoryinfo.GetFiles();//得到文件夹中图片目录

    private List <string > GetUserImages()
{
List<string> images = new List<string>();
if (Directory.Exists(myPath) == false)
{
MessageBox.Show("图片路径"+myPath +"不存在");
return images;
}
DirectoryInfo directoryinfo = new DirectoryInfo(myPath);//new 一个DirectoryInfo实例
FileInfo[] files = directoryinfo.GetFiles();//得到文件夹中图片目录
if (files != null)
{
foreach ( FileInfo file in files)
{
images.Add(file.FullName);//返回完整路径 }
}
return images; }

(2)第二步:根据图片路径和索引值,创建InteractiveVisual3D对象

  private void LoadImageToViewport3D(  List <string > images)
{ if (images ==null)
{
return ;
}
for (int i = 0; i <images.Count;i++ )
{
string image = images[i];
InteractiveVisual3D visual3D = CreateInteractiveVisual3D(image,i);
this.viewport3D.Children.Add(visual3D);
}
this.ReLayoutInteractiveVisual3D();
}

创建3D对象包含几何图形、变换和内容

 private InteractiveVisual3D CreateInteractiveVisual3D(string imagefile,int index)
{
InteractiveVisual3D visual3D = new InteractiveVisual3D();
visual3D.Visual = this.CreatVisual3D(imagefile ,index);
visual3D.Geometry = this.CreateGeometry();
visual3D.Transform = this.CreateTransform();
return visual3D;
}

①3D对象内容:

实例Border对象,里面添加Image和TextBlock两个对象,分别显示图片和图片名称。

bitmapimage =newBitmapImage (new Uri(imagefile,UriKind.Relative));

获得图片的路径。

String  imageName= imagefile.Substring(imagefile.LastIndexOf('\\')+1, imagefile.LastIndexOf('.')-imagefile.LastIndexOf('\\')-1);根据正则表达式截取图片名称

②根据图片像素进行等比缩放,返回一个图像宽度和高度,用来构建几何形状

  BitmapImage bitmapimage=null;
try
{
bitmapimage =new BitmapImage (new Uri(imagefile,UriKind.Relative));
_3DiamgeWidth = ConvertImageScale(bitmapimage.PixelWidth,bitmapimage.PixelHeight,0.7,0.7)[0];
_3DimageHeight = ConvertImageScale(bitmapimage.PixelWidth,bitmapimage.PixelHeight,0.7,0.7)[1]; }
catch{}

MeshGeometry3D geometry = new MeshGeometry3D();//实例MeshGeometry3D对象,根据返回值确定空间四个坐标,本例在z平面,所以z坐标为0.

Point3DpLeftTop = new Point3D(-1, _3DimageHeight, 0); pLeftTop.Offset((1.0 -_3DiamgeWidth) / 2.0, (1.0 - _3DimageHeight) / 2.0, 0);

geometry.Positions.Add(pLeftTop);//

……

geometry.TriangleIndices = new Int32Collection();//定义三角形

geometry.TriangleIndices.Add(0);

geometry.TriangleIndices.Add(1);

……

geometry.TextureCoordinates = new PointCollection();//对朝向摄像机的立方体面进行映射

geometry.TextureCoordinates.Add(new Point(0, 0));

……

③变换,本例运用两种变换 RotateTransform3D、TranslateTransform3D

   private Transform3DGroup CreateTransform()
{
Transform3DGroup transform3DGroup = new Transform3DGroup();
transform3DGroup.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D (0,1,0),0)));
transform3DGroup.Children.Add(new TranslateTransform3D(new Vector3D()));
return transform3DGroup;
}

(3)布局

初始化:根据索引和当前CurrentMiddleIndex布局,初始CurrentMiddleIndex值为0.

disToMiddleIndex = index - currentmiddleindex;

当小于0时,角度为15,Offsetx值向左移动,Offsetz向z轴负方向移动;当大于0时,角度为-15,Offsetx值向右移动,Offsetz向z轴负方向移动;

鼠标点击事件:当鼠标点击后,this.CurrentMiddleIndex = index;将当前索引值赋值给CurrentMiddleIndex,如果CurrentMiddleIndex值改变,调用CurrentMiddleIndexChangedCallBack()函数进行重新布局。

  private static void CurrentMiddleIndexChangedCallBack(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
{
MainWindow mainWindow = sender as MainWindow;
if (mainWindow!=null)
{
mainWindow.ReLayoutInteractiveVisual3D();
}
}

鼠标点击后图片放大事件:

鼠标第一次点击时,当前Offsetz值为0;

  if(((TranslateTransform3D)(((Transform3DGroup)visual3D.Transform).Children[1])).OffsetZ>0)
{
offsetZ = 0;
}
else {
offsetZ = 1;
}

当为0时,将Offsetz值改为1,拉近与Camera距离,产生图片放大效果,当再次点击Offsetz值为1,Offsetz值将还原为0,图片还原。

3.   源代码

http://download.csdn.net/detail/m0_37591671/9797092

WPF3D图片轮播效果的更多相关文章

  1. jQuery个性化图片轮播效果

    jQuery个性化图片轮播效果 购物产品展示:图片轮播器<效果如下所示> 思路说明: 每隔一段时间,实现图片的自动切换及选项卡选中效果,鼠标划入图片动画停止,划出或离开动画开始 两个区域: ...

  2. CSS3图片轮播效果

    原文:CSS3图片轮播效果 在网页中用到图片轮播效果,单纯的隐藏.显示,那再简单不过了,要有动画效果,如果是自己写的话(不用jquery等),可能要费点时间.css3的出现,让动画变得不再是问题,而且 ...

  3. js实现淘宝首页图片轮播效果

    原文:http://ce.sysu.edu.cn/hope2008/Education/ShowArticle.asp?ArticleID=10585 <!DOCTYPE html> &l ...

  4. 超实用的JavaScript代码段 Item3 --图片轮播效果

    图片轮播效果 图片尺寸 统一设置成:490*170px; 一.页面加载.获取整个容器.所有放数字索引的li及放图片列表的ul.定义放定时器的变量.存放当前索引的变量index 二.添加定时器,每隔2秒 ...

  5. JQ 实现轮播图(3D旋转图片轮播效果)

    轮播图效果如下: 代码: <!DOCTYPE html> <html xmlns="/www.w3.org/1999/xhtml"> <head> ...

  6. ios图片轮播效果

    代码地址如下:http://www.demodashi.com/demo/11959.html ImageCarousel 简单封装的图片轮播器 内存过大由于我加载的图片分辨率较高(4k) 文件目录 ...

  7. axure 动态面板实现图片轮播效果(淘宝)

    淘宝中经常可以看到店铺中的图片轮播效果,本经验将通过axure7.0实现 工具/原料   axure7.0 方法/步骤     下载需要轮播的图片   将图片引入至axure中,将引入的第一张图片转为 ...

  8. js图片轮播效果实现代码

    首先给大家看一看js图片轮播效果,如下图 具体思路: 一.页面加载.获取整个容器.所有放数字索引的li及放图片列表的ul.定义放定时器的变量.存放当前索引的变量index 二.添加定时器,每隔2秒钟i ...

  9. 使用FlaycoBanner实现图片轮播效果(加载网络图片)

    FlaycoBanner是一个开源图片轮播框架,支持android2.2及以上: git地址:https://github.com/H07000223/FlycoBanner_Master 在andr ...

随机推荐

  1. 随手可得的Application对象

    在Android的开发其中,Application和Context对象应该是我们接触最多的对象了,特别是Context对象. 当我们在某个Activity或者Service其中时,因为它们本身就是Co ...

  2. 【solr基础教程之九】客户端 分类: H4_SOLR/LUCENCE 2014-07-30 15:28 904人阅读 评论(0) 收藏

    一.Java Script 1.由于Solr本身可以返回Json格式的结果,而JavaScript对于处理Json数据具有天然的优势,因此使用JavaScript实现Solr客户端是一个很好的选择. ...

  3. 【25.64%】【codeforces 570E】Pig and Palindromes

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. Django之模板过滤器

    Django 模板过滤器也是我们在以后基于 Django 网站开发过程中会经常遇到的,如显示格式的转换.判断处理等.以下是 Django 过滤器列表,希望对为大家的开发带来一些方便. 一.形式:小写 ...

  5. [CSS Flex] Justify-content

    justify content contol how element inside flex box align, it can be "right / end", or &quo ...

  6. 【转载】FormsAuthenticationTicket 对象

    1.使用Forms验证存储用户自定义信息 Forms验证在内部的机制为把用户数据加密后保存在一个基于cookie的票据FormsAuthenticationTicket中,因为是经过特殊加密的,所以应 ...

  7. VO对象通过groovy模板映射XML文件

    介绍 之前写过JAVA+XSLT相关的技术博客,近期研究了一个开源工具包org.codehaus.groovy,处理VO对象和XML文件映射很方便. 简言之:将VO对象中的属性(包含Collectio ...

  8. javascript 验证附件大小

    ///验证单个文件不能超过30M function onChangeFile() { ///定义布尔类型的返回结果,初始值为false(默认不超过30M) var sResult = false; / ...

  9. Erlang入门

    Erlang简史(翻译) Erlang入门(二)—并发编程 Erlang入门(三)——分布式编程 Erlang入门(四)——错误处理和鲁棒性 Erlang入门(五)——补遗

  10. 【b404】虫食算

    Time Limit: 1 second Memory Limit: 50 MB [问题描述] 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简单 ...