Welcome

首页 / 软件开发 / Silverlight / Silverlight游戏中的WriteableBitmap技术可行性报告

Silverlight游戏中的WriteableBitmap技术可行性报告2011-09-29 博客园 包建强目录设置如下:

情形1:将png文件都设置为Resource,Do not copy。

指定Image的Source代码:

spirit.Source = new BitmapImage(new Uri(@"Player/" + count + ".png", UriKind.Relative));

注意这里使用的是相对路径,是当前MainPage.xaml相对于图片的位置,而不能使用服务器路径。

如果我们在Spirit中指定Image的Source,就是说相对路径变了,那么代码要写为:

Body.Source = new BitmapImage(new Uri(@"../Player/2.png", UriKind.Relative));

在这种情形下,所有图片都被作为资源而嵌入到dll中,观察xap中的组织结构,可以证实我们的结论 :

情形2:将png文件都设置为Content,Copy if newer。

指定Image的Source代码:

spirit.Source = new BitmapImage(new Uri(@"/Player/" + count + ".png", UriKind.Relative));

注意这里使用的是服务器路径,而不能使用相对路径。

使用服务器路径的一个好处是,无论xaml位于那个目录下,都可以无视,例如上面的那个Spirit控件 :

Body.Source = new BitmapImage(new Uri(@"/Player/2.png", UriKind.Relative));