与众不同 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 相机和照片: 镜头的可扩展性, 图片的可扩展性, 图片的自动上传扩展的更多相关文章
- 与众不同 windows phone (41) - 8.0 相机和照片: 通过 AudioVideoCaptureDevice 捕获视频和音频
[源码下载] 与众不同 windows phone (41) - 8.0 相机和照片: 通过 AudioVideoCaptureDevice 捕获视频和音频 作者:webabcd 介绍与众不同 win ...
- 与众不同 windows phone (42) - 8.0 相机和照片: 通过 PhotoCaptureDevice 捕获照片
[源码下载] 与众不同 windows phone (42) - 8.0 相机和照片: 通过 PhotoCaptureDevice 捕获照片 作者:webabcd 介绍与众不同 windows pho ...
- 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector
[源码下载] 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector 作者:webabcd 介绍与众不同 windows phone 8.0 之 新的 ...
- 与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask
[源码下载] 与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirec ...
- 与众不同 windows phone (36) - 8.0 新的瓷贴: FlipTile, CycleTile, IconicTile
[源码下载] 与众不同 windows phone (36) - 8.0 新的瓷贴: FlipTile, CycleTile, IconicTile 作者:webabcd 介绍与众不同 windows ...
- 与众不同 windows phone (37) - 8.0 文件系统: StorageFolder, StorageFile, 通过 Uri 引用文件, 获取 SD 卡中的文件
[源码下载] 与众不同 windows phone (37) - 8.0 文件系统: StorageFolder, StorageFile, 通过 Uri 引用文件, 获取 SD 卡中的文件 作者:w ...
- 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议
[源码下载] 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议 作者:webabcd 介绍与众不同 windows ...
- 与众不同 windows phone (39) - 8.0 联系人和日历
[源码下载] 与众不同 windows phone (39) - 8.0 联系人和日历 作者:webabcd 介绍与众不同 windows phone 8.0 之 联系人和日历 自定义联系人存储的增删 ...
- 与众不同 windows phone (40) - 8.0 媒体: 音乐中心的新增功能, 图片中心的新增功能, 后台音乐播放的新增功能
[源码下载] 与众不同 windows phone (40) - 8.0 媒体: 音乐中心的新增功能, 图片中心的新增功能, 后台音乐播放的新增功能 作者:webabcd 介绍与众不同 windows ...
随机推荐
- 通过transform属性改变图片的位置大小等信息
对UIImageView的位置大小方向的改变可以通过改变其transform属性值实现. 位置改变: var transform = CGAffineTransformMakeTranslation( ...
- ASP.NET 4.0 forms authentication issues with IE11
As I mentioned earlier, solutions that rely on User-Agent sniffing may break, when a new browser or ...
- NSObject的load和initialize方法(转)
全文转载自:http://www.cocoachina.com/ios/20150104/10826.html 在Objective-C中,NSObject是根类,而NSObject.h的头文件中前两 ...
- 130 个你需要了解的 vim 命令
基础 :e filename Open filename for edition :w Save file :q Exit Vim :q! Quit without saving :x Write f ...
- 解决在IE下LABEL中IMG图片无法选中RADIO的几个方法
转http://www.cnblogs.com/chenxianbin89/archive/2012/11/25/2787258.html . 方法三,THML代码控制: 在IMG中加一个属性,dis ...
- tomcat的网站屏蔽IP的方法
<Host> <Valve className="org.apache.catalina.valves.RemoteAddrValve" deny=" ...
- c/c++: c++继承 内存分布 虚表 虚指针 (转)
http://www.cnblogs.com/DylanWind/archive/2009/01/12/1373919.html 前部分原创,转载请注明出处,谢谢! class Base { pu ...
- WCF 遇到的问题
1.只有项目的net版本2.0以上的才可以引用到wcf的类库 2.HTTP 错误 404.17 - Not Found 映射问题 WCF服务建立好,提示这个错误,缺少映射问题,要将应用程序池和项 ...
- [转]Visual Studio技巧之打造拥有自己标识的代码模板
可能经过很多博客的介绍,大家都知道代码段的使用,使用代码段可以很方便地生成一些常用的代码格式,确实对我们开发很方便.在团队开发中或者在某些情况下我们经常可能还会希望使用Visual Studio生成的 ...
- mount分区为读写属性
对于只读文件系统, 如果想要挂载为可读写的, 需要重新mount下, 如将config分区mount为读写的分区: mount -o remount,rw /config