适用于Windows Phone的图像发送应用程序

本文关键字:应用程序 图像 Windows Phone 适用于 | 更新日期: 2023-09-27 18:29:43

我正在为Windows Phone 8.1开发应用程序,该应用程序具有:

带有文件打开选取器的页面,用于从图库和第二页中拍照将这张照片作为邮件附件发送。

我如何拍摄这张精选的照片并通过电子邮件发送

我试图寻找一些解决方案,但到目前为止没有任何运气。

有什么建议吗?

代码在常规c#xaml中,我在Visual Studio 2015中使用Windows Phone 8.1。

适用于Windows Phone的图像发送应用程序

您可以在一个步骤中使用此解决方案来解决问题。

        /// <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应用程序,请忽略或删除答案。

我相信在WP8.1中,您需要实现IContinuationManager,它将帮助您获得用户选择的图像。首先,您需要一个打开Gallery 的活动

 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);

此链接中的更多详细信息http://developerpublish.com/windows-phone-8-1-and-windows-runtime-apps-how-to-2-send-emails-with-attachment-in-wp-8-1/

希望这能有所帮助!