我正在开发适用于Windows Phone 8.1的应用程序:
带有文件打开选择器的页面,可以从图库和第二页拍摄照片 将该一张照片作为带有消息的电子邮件附件发送。
我如何拍摄这张照片并通过电子邮件发送。
我试图寻找一些解决方案,但到目前为止没有任何运气。
有什么建议吗?
代码是常规c#
和xaml
,我在Visual Studio 2015中使用Windows Phone 8.1。
答案 0 :(得分:0)
您可以一步到位地使用此解决方案。
/// <summary>
/// Taking photo from the gallery
/// </summary>
private void SharePhotoClick(object sender, RoutedEventArgs e)
{
PhotoChooserTask ph=new PhotoChooserTask();
ph.Completed += ph_Completed;
ph.Show();
}
/// <summary>
/// Sharing the photo to social media including email
/// </summary>
void ph_Completed(object sender, PhotoResult e)
{
ShareMediaTask smt = new ShareMediaTask();
smt.FilePath = e.OriginalFileName;
smt.Show();
}
希望这有帮助!
注意:如果您正在开发通用wp应用程序,请忽略或删除答案。
答案 1 :(得分:0)
我相信WP8.1你需要实现IContinuationManager,它将帮助你获得用户选择的图像。 首先,您需要一个打开图库的活动
private void PickAFileButton_Click(object sender, RoutedEventArgs e)
{
...
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
// Launch file open picker and caller app is suspended
// and may be terminated if required
openPicker.PickSingleFileAndContinue();
}
选择图像后,调用app.xaml.cs中的OnActivated()方法,您需要继续管理器来获取所选文件的数据。
protected async override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args);
var continuationManager = new ContinuationManager();
var rootFrame = CreateRootFrame();
await RestoreStatusAsync(args.PreviousExecutionState);
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage));
}
var continuationEventArgs = e as IContinuationActivatedEventArgs;
if (continuationEventArgs != null)
{
Frame scenarioFrame = MainPage.Current.FindName("ScenarioFrame") as Frame;
if (scenarioFrame != null)
{
// Call ContinuationManager to handle continuation activation
continuationManager.Continue(continuationEventArgs, scenarioFrame);
}
}
Window.Current.Activate();
}
现在,延续管理器将为您处理激活。
case ActivationKind.PickSaveFileContinuation:
var fileSavePickerPage = rootFrame.Content as IFileSavePickerContinuable;
if (fileSavePickerPage != null)
{
fileSavePickerPage.ContinueFileSavePicker(args as FileSavePickerContinuationEventArgs);
}
break;
case ActivationKind.PickFolderContinuation:
var folderPickerPage = rootFrame.Content as IFolderPickerContinuable;
if (folderPickerPage != null)
{
folderPickerPage.ContinueFolderPicker(args as FolderPickerContinuationEventArgs);
}
break;
case ActivationKind.WebAuthenticationBrokerContinuation:
var wabPage = rootFrame.Content as IWebAuthenticationContinuable;
if (wabPage != null)
{
wabPage.ContinueWebAuthentication(args as WebAuthenticationBrokerContinuationEventArgs);
}
break;
}
此处提供的所有代码段 https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
完成此操作后,您可以获取数据并将其保存到文件中,并将该文件附加到电子邮件中。
EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient("test@abc.com"));
email.Subject = "Test";
var file = await GetFile();
email.Attachments.Add(new EmailAttachment(file.Name, file));
await EmailManager.ShowComposeNewEmailAsync(email);
希望这有帮助!