Windows Phone上的照片应用程序的可扩展性

照片应用程序可扩展性允许开发人员将自己的照片应用程序与内嵌的windows phone的内置照片应用程序无缝集成。 通过SPV中的extras菜单项,最终用户可以轻松访问自己的应用程序而无需离开windows phone的主照片应用程序。 这将有助于防止在SPV以外试图改变照片而造成不必要的混淆。 这种在内置照片应用内的扩展性将为用户和照片体验之间更直接、 直观的互动铺平道路。

SPV允许应用程序使用一致的方式显示本地的,下载的,或者在线的照片。你可以在windows phone上通过导航到windows phone pictures应用程序然后选择任意一张图片来体验SPV,在照片上点击然后保持按下状态几秒钟,菜单就会被激活。

 

设计和实现机制

 

本节将讨论识别一个照片应用程序并且将之列在SPV的extras...菜单项里所需要的xml文件。

开发者需要添加一个名为 Extras.xml 的脚本文件到自己的 Visual Studio工程中。内嵌的照片应用将会从应用程序安装路径检索这个文件,解析其内容,并且确定此应用程序是否是一个照片应用程序。下面是一个Extras.xml 的例子:

<?xml version=1.0 encoding=utf-8 ?>

<Extras>
  <PhotosExtrasApplication>
    <Enabled>true</Enabled>
    <StorageFolder>[FolderName]</StorageFolder>
  </PhotosExtrasApplication>
</Extras>

 

下表列出了定义的元素结构:

 

Element

Description

<Extras></Extras>

This is the root element on the page.

<PhotosExtrasApplication></PhotosExtrasApplications>

This parent element holds the child elements <Enabled> and <StorageFolder>.

<Enabled></Enabled>

Value = Bool: The element designates whether photo extensibility is enabled in the application. A value of true indicates that it is enabled.

<StorageFolder></StorageFolder>

Value=String: The <StorageFolder> element contains the name of the isolated storage folder that will hold a retrieved photo. When you specify a name, this folder will automatically be created at application runtime. When a user selects a photo from the SPV and launches your application, the photo will be added to the folder. For more information on how to retrieve a photo from this folder through code see How to: Create a Photo Extras Application for Windows Phone.

 


extras 菜单项仅仅在下面两个条件都满足的情况下才会显示在SPV菜单中:

  • 有一个照片应用程序已经被安装在设备中

  • 用户在SPV里点击了一张照片

 

 

启动点和用户流程

在windows phone上应用程序有两个启动入口,每一种有相应的用户流程:

  • 从应用程序列表启动. 这是默认的启动方式。应用程序列表启动不会将照片作为参数传递给你的应用程序,程序必须调用PhotoChooserTask.Show 方法来允许用户从相册里选择一张照片。对于用户来说用户流程要先启动应用程序然后选择一张照片。
  •  从extras菜单启动- 这是特别的启动程序的方式。用户流程是先选择一张照片然后启动应用程序。当应用程序从extras菜单启动时,你的应用程序里应该支持可选的用户流程来跳过选择照片这一步,然后程序将JPG文件作为输入来处理。

具体步骤为:

  • 创建Extras.xml 文件 - 这个文件是使你的应用程序在SPV菜单里可见所必须的。

  • 检索选择的照片 - 一旦用户选择了照片,它将会被放置到isolated storage里, 将它解码成WriteableBitmap对象, 然后再你的程序里显示它。

 添加Extras.xml文件到你的项目中:

1.首先加入下面的名字空间

using System.Windows.Media.Imaging;
using Microsoft.Phone.Tasks;
using Microsoft.Phone;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Navigation;
2.

在项目中添加一个文件, 名字必须为:Extras.xml

内容为:

<Extras>
  <PhotosExtrasApplication>
    <Enabled>true</Enabled>
    <StorageFolder>Incoming</StorageFolder>
  </PhotosExtrasApplication>
</Extras>
重要提示1:Extras.xml文件的Copy to Output Directory 属性必须设置为Copy always .这样就能确保此文件会被检测为一个照片扩展程序。
重要提示2:<StorageFolder>Incoming</StorageFolder>中的Incoming字符串可以改成你愿意的名称,同时后台代码中的接收照片部分的代码也相应要修改。


检索选择的照片

下面的代码演示了如何接收用户选择的照片并且解码为WriteableBitmap 对象。

1.在MainPage.xaml.cs 中添加下面的代码:

         protected override void OnNavigatedTo(NavigationEventArgs e)

        {

            //Gets a dictionary of query string keys and values

            IDictionary<string, string> queryStrings = this.NavigationContext.QueryString;

 

            //This code ensures that there is at least one key in the query string, and check if the "token" key is present.

            if (queryStrings.ContainsKey("token"))

            {

                //This code retrieves the picture from the local Zune Media Database using the token passed to the application.

                MediaLibrary library = new MediaLibrary();

                Picture picture = library.GetPictureFromToken(queryStrings["token"]);

 

                //Creates WriteableBitmap object and adds to the Image control Source property.

                BitmapImage bitmap = new BitmapImage();

                bitmap.SetSource(picture.GetImage());

                WriteableBitmap picLibraryImage = new WriteableBitmap(bitmap);

                retrievePic.Source = picLibraryImage;

            }

        }

2.将你的程序部署到windows phone设备上

3.在Windows Phone的开始页面,点击照片应用程序,选择一张图片,然后点击以放大查看图片

4.点击放大后的图片保持按下状态几秒钟将会弹出一个菜单,最后一个菜单项是extras..., 选择这项。

5. 在Extras页面选择你的应用程序名字,你的应用程序就会启动,并且刚才的图片会自动传递给你的应用程序。

6.如何处理传入的图片就是你自己的事情了。

 

转载于:https://www.cnblogs.com/nio-nio/archive/2010/09/08/1821263.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值