使用DeepZoom打造变形金刚SHOW
DeepZoom技术是Silverlight 2中加入的全新特性,你可以把DeepZoom简单的理解为一项基于位图的局部加载和缩放的技术,
http://memorabilia.hardrock.com/就是这项技术的典型应用,如图所示。
这个页面中包括300幅高分辩率的位图,可想而知,如果将这些图片按顺序全部都下载到客户端浏览器将需要耗费大量的时间和带宽,并且用户关心的内容也不能够在第一时间查看,但是DeepZoom技术可以把一幅或一组图片分割成多个部分,根据用户浏览图像的位置来进行选择性的加载,当用户查看一幅清晰度很高、容量较大的图片时,DeepZoom仅仅加载用户需要浏览位置的内容,并且用户可以轻松的使用鼠标键来拖动和缩放图片,这样极大的减少了用户等待的时间,为用户带来一种很酷的交互方式和浏览体验,放大图片如图所示。
对于开发者而言,应用DeepZoom技术,你只需要下载并安装DeepZoomComposer,DeepZoomComposer程序工作界面如图所示。
使用DeepZoomComposer可以让你快速完成具有DeepZoom技术的Silverlight应用程序,下面就使用DeepZoomComposer制作一个变形金刚SHOW程序。
首先在DeepZoomComposer启动界面中创建一个新项目,如图所示。
DeepZoom工作界面主要分为三个工作区,同时又是制作DeepZoom的三个步骤,分别是导入、构图和输出。
导入:
在导入区中你可以将项目中所需要的图片导入到DeepZoomComposer项目中,点击Add Image按钮选择需要导入的图片,导入的过程中会出现importing进度条窗口,导入完成后的图片会在右侧列表中显示出来。
构图:
完成图片的导入后,你就可以将对程序界面中需要用到图片的拖动到排列区中,在这里你可以使用下方的布局工具,如图所示,对图片的位置、大小和对齐方式进行布局,右侧的All Image选项是显示项目导入全部图片列表,Layer VIEw是显示那些在构图区中用到的图片列表。
输出:
完成导入和排列后,一个简单的DeepZoom应用程序就完成了,通过DeepZoomComposer的输入功能将完成的DeepZoom应用程序输入为一个Silverlight 2应用程序项目,输出前可以预览程序运行结果,如图所示。
选择Silverlight Export选项,在Silverlight Export选项中,你需要输入Silverlight应用程序名称和输出文件夹,并选择输出的图片类型,点击Export(输出)会出现输出处理进度窗口,如图所示,完成后会显示输出完成窗口,如图所示,这样一个应用DeepZoom技术的Silverlight 2应用程序项目就完成了,使用Visual Studio 2008打开并运行输出的文件夹中的Silverlight 2项目,程序运行结果如图所示。
XAML代码:
<UserControl x:Class="DeepZoomProject.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WIDth="780" Height="450">
<GrID Background="White">
<MultiScaleImage x:name="msi" WIDth="780" Height="400"/>
</GrID>
</UserControl>
C#代码:
using System;
using System.Collections.Generic;
using System.linq;
using System.Net;
using System.windows;
using System.windows.Controls;
using System.windows.documents;
using System.windows.input;
using System.windows.Media;
using System.windows.Media.Animation;
using System.windows.Shapes;
namespace DeepZoomProject
{
public partial class Page : UserControl
{
//
// Based on prior work done by Lutz Gerhard,Peter Blois,and Scott Hanselman
//
Point lastMousePos = new Point();
double _zoom = 1;
bool mousebuttonpressed = false;
bool mouseIsDragging = false;
Point dragOffset;
Point currentposition;
public double ZoomFactor
{
get { return _zoom; }
set { _zoom = value; }
}
public Page()
{
InitializeComponent();
//
// We are setting the source here,but you should be able to set the Source property via
//
this.msi.source = new DeepZoomImageTileSource(new Uri("GeneratedImages/dzc_output.xml",UriKind.relative));
//
// Firing an event when the MultiScaleImage is Loaded
//
this.msi.Loaded += new RoutedEventHandler(msi_Loaded);
//
// Firing an event when all of the images have been Loaded
//
this.msi.ImageOpenSucceeded += new RoutedEventHandler(msi_ImageOpenSucceeded);
//
// Handling all of the mouse and keyboard functionality
//
this.MouseMove += delegate(object sender,MouseEventArgs e)
{
if (mousebuttonpressed)
{
mouseIsDragging = true;
}
this.lastMousePos = e.Getposition(this.msi);
};
this.MouseleftbuttonDown += delegate(object sender,MousebuttonEventArgs e)
{
mousebuttonpressed = true;
mouseIsDragging = false;
dragOffset = e.Getposition(this);
currentposition = msi.VIEwportOrigin;
};
this.msi.MouseLeave += delegate(object sender,MouseEventArgs e)
{
mouseIsDragging = false;
};
this.MouseleftbuttonUp += delegate(object sender,MousebuttonEventArgs e)
{
mousebuttonpressed = false;
if (mouseIsDragging == false)
{
bool shiftDown = (Keyboard.ModifIErs & ModifIErKeys.Shift) == ModifIErKeys.Shift;
ZoomFactor = 2.0;
if (shiftDown) ZoomFactor = 0.5;
Zoom(ZoomFactor,this.lastMousePos);
}
mouseIsDragging = false;
};
this.MouseMove += delegate(object sender,MouseEventArgs e)
{
if (mouseIsDragging)
{
Point newOrigin = new Point();
newOrigin.X = currentposition.X - (((e.Getposition(msi).X - dragOffset.X) / msi.ActualWIDth) * msi.VIEwportWIDth);
newOrigin.Y = currentposition.Y - (((e.Getposition(msi).Y - dragOffset.Y) / msi.ActualHeight) * msi.VIEwportWIDth);
msi.VIEwportOrigin = newOrigin;
}
};
new MouseWheelHelper(this).Moved += delegate(object sender,MouseWheelEventArgs e)
{
e.Handled = true;
if (e.Delta > 0)
ZoomFactor = 1.2;
else
ZoomFactor = .80;
Zoom(ZoomFactor,this.lastMousePos);
};
}
voID msi_ImageOpenSucceeded(object sender,RoutedEventArgs e)
{
//If collection,this gets you a List of all of the MultiScaleSubImages
//
//foreach (MultiScaleSubImage subImage in msi.SubImages)
//{
// // Do something
//}
}
voID msi_Loaded(object sender,RoutedEventArgs e)
{
// Hook up any events you want when the image has successfully been opened
}
public voID Zoom(double zoom,Point pointToZoom)
{
Point logicalPoint = this.msi.ElementTologicalPoint(pointToZoom);
this.msi.ZoomAboutLogicalPoint(zoom,logicalPoint.X,logicalPoint.Y);
}
/*
* Sample event handlerrs tIEd to the Click of event of varIoUs buttons for
* showing all images,zooming in,and zooming out!
*
private voID ShowAllClick(object sender,RoutedEventArgs e)
{
this.msi.VIEwportOrigin = new Point(0,0);
this.msi.VIEwportWIDth = 1;
ZoomFactor = 1;
}
private voID zoomInClick(object sender,RoutedEventArgs e)
{
Zoom(1.2,new Point(this.ActualWIDth / 2,this.ActualHeight / 2));
}
private voID zoomOutClick(object sender,RoutedEventArgs e)
{
Zoom(.8,this.ActualHeight / 2));
}
* */
}
}
放大后效果:
Deep Zoom Composer 下载地址:http://www.microsoft.com/downloads/details.aspx?familyID=457b17b7-52bf-4bda-87a3-fa8a4673f8bf&displaylang=en
总结以上是内存溢出为你收集整理的使用DeepZoom打造超酷变形金刚SHOW全部内容,希望文章能够帮你解决使用DeepZoom打造超酷变形金刚SHOW所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)