简体   繁体   English

如何拍照并通过电子邮件发送?

[英]How to take a photo and email it?

I'd like the user to take a photo and then open an email dialog with the photo attached. 我希望用户拍照,然后打开附有照片的电子邮件对话框。 So far I got this: 到目前为止我得到了这个:

private void btnSubmitPhoto_Click(object sender, EventArgs e) 
{ 
    CameraCaptureTask cameraCaptureTask = new CameraCaptureTask(); 
    cameraCaptureTask.Completed += cameraCaptureTask_Completed; 
    cameraCaptureTask.Show(); 
} 

private void cameraCaptureTask_Completed(object sender, PhotoResult e) 
{ 
    if (e.TaskResult == TaskResult.OK) 
    { 
        currentImage = new BitmapImage(); 
        currentImage.SetSource(e.ChosenPhoto); 

        EmailComposeTask ect = new EmailComposeTask();     
    }             
}    

I don't see how to add an attachment to the EmailComposeTask. 我没有看到如何向EmailComposeTask添加附件。 Am I missing something? 我错过了什么吗?

It is not possible with the current framework tools to add an attachment to an email by using the EmailComposeTask . 使用当前框架工具无法使用EmailComposeTask向电子邮件添加附件。 If you need this functionality, you will have to manually handle email sending yourself by using a web service. 如果您需要此功能,则必须使用Web服务手动处理自己发送的电子邮件。

In addition to not being able to send attachments there is an issue with the way that you are using the CameraCaptureTask . 除了无法发送附件之外,您使用CameraCaptureTask的方式也存在问题。

Because this task is a chooser you must code it's use to account for tombsoning. 由于此任务是一个选择器,因此您必须对其进行编码,以便对其进行编码。

In practical terms, this means that yoour instance of CameraCaptureTask must be at a class level and the completed event handler should be subscribed too in the page constructor. 实际上,这意味着yoour的实例CameraCaptureTask必须处于一流水平,并已完成事件处理程序也应该在网页的构造进行认购。

If you don't do this then the page won't know how to handle the information returned when the task returns. 如果您不这样做,那么页面将不知道如何处理任务返回时返回的信息。

Your code will need to look something like this: 您的代码需要看起来像这样:

public partial class MainPage : PhoneApplicationPage
{
    CameraCaptureTask cct = new CameraCaptureTask();

    public MainPage()
    {
        InitializeComponent();

        // Any other initialization tasks

        cct.Completed += new EventHandler<PhotoResult>(cct_Completed);
    }

    void cct_Completed(object sender, PhotoResult e)
    {
        // Do something with `e`
    }

    // Or some other appropriate event
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        cct.Show();
    }

Please Note. 请注意。 this is the case for all choosers, but not launchers. 所有选择器都是如此,但不是发射器。

Update: 更新:
The reason for this is due to the way the page is "rehydrated" after the application is tombstoned to open the chooser. 造成这种情况的原因是在应用程序被逻辑删除以打开选择器之后页面被“重新水化”的方式。

When returning from displaying the chooser a new instance of the page will be created. 从显示选择器返回时,将创建页面的新实例。 This will, therefore, not include any record of event handlers subscribed in previous instances. 因此,这将不包括在先前实例中订阅的事件处理程序的任何记录。 Without anything attached to the completed handler your code to process the details returned by the chooser will not be called. 如果没有任何附加到已完成的处理程序的任何内容,则不会调用处理选择器返回的详细信息的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM