[源码下载]

与众不同 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. 卖萌的极致!脸部捕捉软件FaceRig让你化身萌宠

    FaceRig是一款以摄像头为跟踪设备捕捉用户脸部动作并转化为数据套用在其他动画模型上的一款软件,能够应用于一些日常的视频社交软件或网站,比如视频通话软件Skype和直播网站Twitch.FaceRi ...

  2. DataInputStream类和RandomAccessFile类的使用方法

    // DataInputStream类实现了DataInput接口,要想从文件中读入二进制数据, // 你需要将DataInputStream与某个字节源相结合,例如FileInputStream / ...

  3. [原]unity5 AssetBundle打包

    本文unity版本5.1.3 一.现有的打包教程: 1.http://liweizhaolili.blog.163.com/blog/static/16230744201541410275298/ 阿 ...

  4. python-推荐

    users={"Angelica": {"Blues Traveler": 3.5, "Broken Bells": 2.0, " ...

  5. 整理PHP_YII环境安装遇到的一些问题

    安装yii遇到的一些问题 操作环境 一.Permissiondenied问题 在终端执行如下命令(注意因为是本地测试环境不需要考虑太多权限问题,如果正式环境请慎重) sudo chmod -R o+r ...

  6. WIN8 下Cisco VPN连接 出现vpn 422 failed to enable virtual adapter错误

    今天在家用VPN软件连接,出现了“vpn 422 failed to enable virtual adapter”的错误,系统安装的是Win8专业版32位,百度了半天又很多方法解决不了,后来发现了一 ...

  7. ODAC(V9.5.15) 学习笔记(十五)数据离线模式

    数据离线模式(Disconnected Mode)是指数据库只有在需要的时候才连接,数据的处理放在客户端内存缓冲区中完成.这样做最大的好处是减少了网络资源依赖,对数据库服务器的资源开销和压力也减少.如 ...

  8. XCActionBar 「Xcode 中的 Alfred」

    下载地址:https://github.com/pdcgomes/XCActionBar 基本命令: (1)「command+shift+8」或者双击「command」键可以打开「动作输入框窗口」 ( ...

  9. linux下备份mysql命令

    一,数据库的备份与导入 1),数据库的备份 1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名例:mysqldump -u dbadmin -p myblog ...

  10. 简谈ubuntu之DIY发行版

    2007.05.13    二十一世纪到了,每个人都强调自己的个性,于是一种叫做DIY的东西悄然兴起. 操作系统作为全人类智慧的结晶,自然DIY起来难度极大,因而DIY出一个操作系统成就感绝对比买宜家 ...