[源码下载]

与众不同 windows phone (43) - 8.0 相机和照片: 镜头的可扩展性, 图片的可扩展性, 图片的自动上传扩展

作者:webabcd

介绍
与众不同 windows phone 8.0 之 相机和照片

  • 镜头的可扩展性
  • 图片的可扩展性
  • 图片的自动上传扩展

示例
1、演示如何将本 app 注册为镜头扩展
CameraAndPhoto/LensExtensibility.xaml

<phone:PhoneApplicationPage
x:Class="Demo.CameraAndPhoto.LensExtensibility"
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="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <Grid Background="Transparent">
<StackPanel Orientation="Vertical"> <TextBlock x:Name="lblMsg" Text="启动相机后,可以通过“滤镜”启动本 app" /> <Button x:Name="btnPhotoCapture" Content="用此 app 照相" Click="btnPhotoCapture_Click" /> <Button x:Name="btnAudioVideoCapture" Content="用此 app 录像" Click="btnAudioVideoCapture_Click" /> </StackPanel>
</Grid> </phone:PhoneApplicationPage>

CameraAndPhoto/LensExtensibility.xaml.cs

/*
* 演示如何将本 app 注册为镜头扩展
*
* 1、需要在 manifest 中增加配置 <Extension TaskID="_default" ExtensionName="Camera_Capture_App" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5631}" />
* 2、在 Assets 根文件夹内添加 3 个文件,作为镜头选取器的图标
* Lens.Screen-WVGA.png - 800*480 15:9
* Lens.Screen-WXGA.png - 1280*768 15:9
* Lens.Screen-720p.png - 1280*720 16:9
*
*
* 注:
* 相关的 UriMapper 参见 MyUriMapper.cs
*
*
* 什么是镜头扩展?
* 就是打开相机后,单击“滤镜”按钮,会出现一排 app 列表,这里的每一个 app 就是一个镜头扩展程序
*/ using System.Collections.Generic;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using System; namespace Demo.CameraAndPhoto
{
public partial class LensExtensibility : PhoneApplicationPage
{
public LensExtensibility()
{
InitializeComponent();
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
IDictionary<string, string> queryStrings = this.NavigationContext.QueryString; if (queryStrings.ContainsKey("fromLens"))
{
lblMsg.Text = "您是通过相机的“滤镜”启动本 app 的";
} base.OnNavigatedTo(e);
} private void btnPhotoCapture_Click(object sender, System.Windows.RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/CameraAndPhoto/PhotoCaptureDeviceDemo.xaml", UriKind.Relative));
} private void btnAudioVideoCapture_Click(object sender, System.Windows.RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/CameraAndPhoto/AudioVideoCaptureDeviceDemo.xaml", UriKind.Relative));
}
}
}

2、演示如何将本 app 注册为图片扩展
CameraAndPhoto/PhotoExtensibility.xaml

<phone:PhoneApplicationPage
x:Class="Demo.CameraAndPhoto.PhotoExtensibility"
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="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <Grid x:Name="LayoutRoot" Background="Transparent">
<StackPanel> <TextBlock Name="lblMsg" TextWrapping="Wrap" Text="用此 app 照个照片,然后再在照片中心打开该照片,再打开上下文菜单,以查看图片扩展的效果" /> <Image Name="img" Width="320" Height="240" Margin="0 10 0 0" /> </StackPanel>
</Grid> </phone:PhoneApplicationPage>

CameraAndPhoto/PhotoExtensibility.xaml.cs

/*
* 演示如何将本 app 注册为图片扩展
*
*
* 1、注册为“共享”扩展:在照片中心的图片的上下文菜单中,单击“共享...”,弹出的 app 列表窗口包含此 app,需要在 manifest 中增加 <Extension TaskID="_default" ExtensionName="Photos_Extra_Share" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5632}" />
*
* 2、注册为“编辑”扩展:在照片中心的图片的上下文菜单中,单击“编辑...”,弹出的 app 列表窗口包含此 app,需要在 manifest 中增加 <Extension TaskID="_default" ExtensionName="Photos_Extra_Image_Editor" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5632}" />
* wp7 时代的做法(与图片的上下文菜单“应用程序...”关联)在 wp8 中已经遭到了弃用,参考:http://www.cnblogs.com/webabcd/archive/2012/07/26/2609357.html
*
* 3、注册为“Photos_Rich_Media_Edit”扩展:会有以下两个特性,以 app 的名字为“WP8 Demo”为例,需要在 manifest 中增加 <Extension TaskID="_default" ExtensionName="Photos_Rich_Media_Edit" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5632}" />
* a) 在照片中心打开由此 app 拍摄的照片时,在屏幕的左下角会有一段文字“由 WP8 Demo 拍摄”
* b) 在照片中心打开由此 app 拍摄的照片后,在其上下文菜单中会多出一项“在 WP8 Demo 中打开”
*
*
* 注:
* 1、需要在 manifest 中增加配置 <Capability Name="ID_CAP_MEDIALIB_PHOTO" />
* 2、相关的 UriMapper 参见 MyUriMapper.cs
*/ using System.Collections.Generic;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Media;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework.Media.PhoneExtensions; namespace Demo.CameraAndPhoto
{
public partial class PhotoExtensibility : PhoneApplicationPage
{
public PhotoExtensibility()
{
InitializeComponent();
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
IDictionary<string, string> queryStrings = this.NavigationContext.QueryString; if (queryStrings.ContainsKey("type"))
{
switch (queryStrings["type"])
{
case "share":
lblMsg.Text = "由“共享...”打开";
break;
case "edit":
lblMsg.Text = "由“编辑...”打开";
break;
case "rich":
lblMsg.Text = "由“在 WP8 Demo 中打开”打开";
break;
}
} // 显示用户选择的图片的预览图
if (queryStrings.ContainsKey("token"))
{
MediaLibrary library = new MediaLibrary();
Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["token"]); BitmapImage bitmapFromPhoto = new BitmapImage();
// GetPreviewImage() - 是扩展方法,来自 Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions
bitmapFromPhoto.SetSource(photoFromLibrary.GetPreviewImage());
img.Source = bitmapFromPhoto;
} base.OnNavigatedTo(e);
}
}
}

3、演示如何将本 app 注册为自动上传的图片扩展
CameraAndPhoto/PhotoAutoUpload.xaml

<phone:PhoneApplicationPage
x:Class="Demo.CameraAndPhoto.PhotoAutoUpload"
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="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True"> <Grid Background="Transparent">
<StackPanel Orientation="Vertical"> <TextBlock x:Name="lblMsg" TextWrapping="Wrap">
<Run>请通过如下方式查找支持自动上传的应用:“设置 -> 应用程序 -> 照片+相机 -> 应用”或者“照片中心 -> 设置 -> 应用”</Run>
<LineBreak />
<Run>你至少会看到一个名为“WP8 Demo”的应用,单击它</Run>
</TextBlock> </StackPanel>
</Grid> </phone:PhoneApplicationPage>

CameraAndPhoto/PhotoAutoUpload.xaml.cs

/*
* 演示如何将本 app 注册为自动上传的图片扩展
*
*
* 1、需要在 manifest 中增加配置 <Extension TaskID="_default" ExtensionName="Photos_Auto_Upload" ConsumerID = "{5B04B775-356B-4AA0-AAF8-6491FFEA5632}" />
* 2、需要通过注册一个资源密集型代理,去执行图片处理(一般是上传图库中的新的图片到服务器)
* 3、关于资源密集型代理参见:http://www.cnblogs.com/webabcd/archive/2012/07/12/2587440.html
* 4、注册为自动上传的 app ,其资源密集型代理不会有 14 天过期一说,但其他限制都仍然是有的
* 5、后台代理的任务一般是检查是否有没同步到你服务器的图片,如果有没同步的就去同步
* 6、当然你不去同步图片到自己的服务器,而是做其他事情,也是没关系的(如果提交 app 时能通过微软审核的话)
*
*
* 注:
* 相关的 UriMapper 参见 MyUriMapper.cs
* 像 SkyDrive 那样的在图片中心提示还有几个未传项,第三方的 app 是无法做到的
*
*
* 什么是自动上传的图片扩展?
* 1、就是可以在“设置 -> 应用程序 -> 照片+相机 -> 应用 -> WP8 Demo”或者“照片中心 -> 设置 -> 应用 -> WP8 Demo”找到的程序
* 2、其资源密集型代理不会有 14 天过期一说,但其他限制都仍然是有的
* 3、一般来说你应该在后台代理检查是否有没同步到你服务器的图片,如果有没同步的就去同步
* 4、一般来说,你应该在“设置 -> 应用程序 -> 照片+相机 -> 应用 -> WP8 Demo”或者“照片中心 -> 设置 -> 应用 -> WP8 Demo”进来的页面内列出正在上传的图片列表和进度
*/ using System.Collections.Generic;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using System; namespace Demo.CameraAndPhoto
{
public partial class PhotoAutoUpload : PhoneApplicationPage
{
public PhotoAutoUpload()
{
InitializeComponent();
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
IDictionary<string, string> queryStrings = this.NavigationContext.QueryString; if (queryStrings.ContainsKey("fromConfig"))
{
lblMsg.Text = "您是通过“设置 -> 应用程序 -> 照片+相机 -> 应用 -> WP8 Demo”或者“照片中心 -> 设置 -> 应用 -> WP8 Demo”启动本 app 的";
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "一般来说,参考 SkyDrive 的话,你应该在这里列出正在上传的图片列表和上传进度,并可以取消或暂停图片的上传任务";
} base.OnNavigatedTo(e);
}
}
}

自定义 UriMapper,用于处理当本 app 由文件打开或协议打开或镜头扩展打开或图片扩展打开时,导航到相关的处理页面
MyUriMapper.cs

/*
* 自定义 UriMapper,用于处理当本 app 由文件打开或协议打开或镜头扩展打开或图片扩展打开时,导航到相关的处理页面
*
* 注:
* 要使此 UriMapper 有效,需要在 App.xaml.cs 中增加 RootFrame.UriMapper = new Demo.MyUriMapper();
*/ using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Windows.Navigation;
using Windows.Phone.Storage.SharedAccess; namespace Demo
{
public class MyUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
string tempUrl = HttpUtility.UrlDecode(uri.ToString()); // 由文件启动本 app 时会通过 /FileTypeAssociation?fileToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 启动
if (tempUrl.StartsWith("/FileTypeAssociation"))
{
// 获取 fileToken
int fileTokenIndex = tempUrl.IndexOf("fileToken=") + ;
string fileToken = tempUrl.Substring(fileTokenIndex); // 获取相关的文件名
string fileName = SharedStorageAccessManager.GetSharedFileName(fileToken); // myLog.log // 获取相关的文件名的扩展名
string fileType = Path.GetExtension(fileName); // 根据文件类型的不同导航到不同的处理页面
switch (fileType)
{
case ".log":
return new Uri("/AssociationLaunching/FileTypeAssociation.xaml?fileToken=" + fileToken, UriKind.Relative);
default:
return new Uri("/MainPage.xaml", UriKind.Relative);
}
}
// 由协议启动本 app 时会通过 /Protocol?encodedLaunchUri=webabcd:xxxxxxxxxx 启动
else if (tempUrl.StartsWith("/Protocol"))
{
// 获取协议的详细信息
int protocolIndex = tempUrl.IndexOf("encodedLaunchUri=") + ;
string protocol = tempUrl.Substring(protocolIndex); // 导航到处理 webabcd 协议的处理页面
return new Uri("/AssociationLaunching/ProtocolAssociation.xaml?protocol=" + protocol, UriKind.Relative);
}
// 由镜头扩展启动本 app 时会通过 /MainPage.xaml?Action=ViewfinderLaunch 启动
else if (tempUrl.Contains("Action=ViewfinderLaunch"))
{
return new Uri("/CameraAndPhoto/LensExtensibility.xaml?fromLens=true", UriKind.Relative);
}
// 由图片扩展之“共享...”启动本 app 时会通过 /MainPage.xaml?Action=ShareContent&FileId={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 启动
else if (tempUrl.Contains("Action=ShareContent"))
{
string fileId = tempUrl.Substring(tempUrl.IndexOf("FileId=") + ).Replace("{", "").Replace("}", "");
return new Uri("/CameraAndPhoto/PhotoExtensibility.xaml?type=share&token=" + fileId, UriKind.Relative);
}
// 由图片扩展之“编辑...”启动本 app 时会通过 /MainPage.xaml?Action=EditPhotoContent&FileId={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 启动
else if (tempUrl.Contains("Action=EditPhotoContent"))
{
string fileId = tempUrl.Substring(tempUrl.IndexOf("FileId=") + ).Replace("{", "").Replace("}", "");
return new Uri("/CameraAndPhoto/PhotoExtensibility.xaml?type=edit&token=" + fileId, UriKind.Relative);
}
// 由图片扩展之“自动上传”启动本 app 时会通过 /MainPage.xaml?Action=ConfigurePhotosUploadSettings 启动
else if (tempUrl.Contains("Action=ConfigurePhotosUploadSettings"))
{
return new Uri("/CameraAndPhoto/PhotoAutoUpload.xaml?fromConfig=true", UriKind.Relative);
}
// 在锁屏设置界面,如果将本 app 设置为背景提供程序,则锁屏界面上会有一个名为“打开应用”的按钮,点击后会通过 /MainPage.xaml?WallpaperSettings=1 启动本 app
else if (tempUrl.Contains("WallpaperSettings=1"))
{
return new Uri("/Others/LockScreen.xaml?WallpaperSettings=1", UriKind.Relative);
} return uri;
}
}
}

OK
[源码下载]

与众不同 windows phone (43) - 8.0 相机和照片: 镜头的可扩展性, 图片的可扩展性, 图片的自动上传扩展的更多相关文章

  1. 与众不同 windows phone (41) - 8.0 相机和照片: 通过 AudioVideoCaptureDevice 捕获视频和音频

    [源码下载] 与众不同 windows phone (41) - 8.0 相机和照片: 通过 AudioVideoCaptureDevice 捕获视频和音频 作者:webabcd 介绍与众不同 win ...

  2. 与众不同 windows phone (42) - 8.0 相机和照片: 通过 PhotoCaptureDevice 捕获照片

    [源码下载] 与众不同 windows phone (42) - 8.0 相机和照片: 通过 PhotoCaptureDevice 捕获照片 作者:webabcd 介绍与众不同 windows pho ...

  3. 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector

    [源码下载] 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector 作者:webabcd 介绍与众不同 windows phone 8.0 之 新的 ...

  4. 与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

    [源码下载] 与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirec ...

  5. 与众不同 windows phone (36) - 8.0 新的瓷贴: FlipTile, CycleTile, IconicTile

    [源码下载] 与众不同 windows phone (36) - 8.0 新的瓷贴: FlipTile, CycleTile, IconicTile 作者:webabcd 介绍与众不同 windows ...

  6. 与众不同 windows phone (37) - 8.0 文件系统: StorageFolder, StorageFile, 通过 Uri 引用文件, 获取 SD 卡中的文件

    [源码下载] 与众不同 windows phone (37) - 8.0 文件系统: StorageFolder, StorageFile, 通过 Uri 引用文件, 获取 SD 卡中的文件 作者:w ...

  7. 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议

    [源码下载] 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议 作者:webabcd 介绍与众不同 windows ...

  8. 与众不同 windows phone (39) - 8.0 联系人和日历

    [源码下载] 与众不同 windows phone (39) - 8.0 联系人和日历 作者:webabcd 介绍与众不同 windows phone 8.0 之 联系人和日历 自定义联系人存储的增删 ...

  9. 与众不同 windows phone (40) - 8.0 媒体: 音乐中心的新增功能, 图片中心的新增功能, 后台音乐播放的新增功能

    [源码下载] 与众不同 windows phone (40) - 8.0 媒体: 音乐中心的新增功能, 图片中心的新增功能, 后台音乐播放的新增功能 作者:webabcd 介绍与众不同 windows ...

随机推荐

  1. openssl命令行工具简介 - RSA操作

    原文链接: http://www.cnblogs.com/aLittleBitCool/archive/2011/09/22/2185418.html 首先介绍下命令台下openssl工具的简单使用: ...

  2. Spring3系列11- Spring AOP——自动创建Proxy

    Spring3系列11- Spring AOP——自动创建Proxy 在<Spring3系列9- Spring AOP——Advice>和<Spring3系列10- Spring A ...

  3. Spring3系列5-Bean的基本用法

    Spring3系列5-Bean的基本用法 本篇讲述了Bean的基本配置方法,以及Spring中怎样运用Bean. 主要内容如下: 一.      Spring中Bean的相互引用 二.      Sp ...

  4. Maven3路程(三)用Maven创建第一个web项目(2)servlet演示

    上一章用Maven新建了web项目成功后,本文演示在此基础上应用servlet. 1.首先修改pom.xml文件,添加servlet依赖 <project xmlns="http:// ...

  5. Asus ubuntu Fn恢复

    sudo sed 's/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/GRUB_CMDLINE_LINUX_DEFAULT="qui ...

  6. SpringMVC Controller 返回值的可选类型

    spring mvc 支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void. ModelAndView @RequestMap ...

  7. Spring MVC 3.x 基本配置

    WEB-INF/web.xml 例1 <?xml version="1.0" encoding="UTF-8"?> <web-app xmln ...

  8. 批量修改Project视图中Prefab的名字

    简要代码如下: using UnityEditor; using UnityEngine; using System.IO; using System.Collections; using Syste ...

  9. 关于Windows Phone平台音乐播放的的技术调研

    希望看到这篇文章的开发者能提供你们的想法,让我们一起来探讨一款wp平台上面一款能流畅播放.能流畅拖拽进入条.只发一次请求就可以缓存的最好的播放器.希望大家能对我下面遇到的问题作出回答. 现在出了Win ...

  10. 疯狂的ASP.NET系列-第一篇:啥是ASP.NET后续

    之前总结到了ASP.NET的七大特点,只总结了2大特点,现继续总结后面的5大特点. (3)ASP.NET支持多语言 这里说的多语言就是多种开发语言,如C#,VB.NET,无论你采用哪种开发语言,最终的 ...