Windows phone picturebox

本文关键字:picturebox phone Windows | 更新日期: 2023-09-27 18:07:49

我正在用c#开发一个windows phone 8.1应用程序。我正在用照相机拍照。图片保存在设备上,我试图在图片框中显示它。我在HTC手机上测试过,效果不错,但在诺基亚Lumia手机上测试时,画面无法加载。有人知道怎么解吗?

下面是我要拍摄的照片代码:

    private void snap_task_Click(object sender, EventArgs e)
    {
        cameraCaptureTask = new CameraCaptureTask();
        cameraCaptureTask.Completed += cameraCaptureTask_Completed;
        cameraCaptureTask.Show();
    }
    void cameraCaptureTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            NavigationService.Navigate(new Uri("/Slika.xaml?fotka=" + e.OriginalFileName, UriKind.Relative));
        }
    }

这是我加载图片的代码

    public Slika()
    {
        InitializeComponent();
        string slika = string.Empty;
        string slika2 = string.Empty;
        this.Loaded += (s, e) =>
        {
            if (NavigationContext.QueryString.TryGetValue("fotka", out slika))
            {
                putanja = slika; /*"/Resources/" + slika + ".png";/**/
                int x = putanja.Length;
                if (x == 1)
                {
                    putanja = "/Resources/" + putanja + ".png";
                    uriPutanja = new Uri(putanja, UriKind.Relative);
                    fotka = new BitmapImage(uriPutanja);
                }
                else
                {
                    uriPutanja = new Uri(putanja, UriKind.Relative);
                    porukaTextBox.Text = putanja;
                    fotka = new BitmapImage(uriPutanja);
                }
            }
            img1.Source = fotka;
        };
    }

p>

本地资源加载在两部手机上都工作得很好,只是if的"else"部分在诺基亚上引起了问题。

Windows phone picturebox

您正在将图像保存在手机的相机卷文件夹中,请尝试将其保存在存储卡上,并尝试是否有效(您只需在手机设置中更改它并说将新照片保存在SD卡上)如果有效,请尝试使用PhotoChooserTask以获取图像。我希望下面的代码能帮到你:

    using Microsoft.Phone.Tasks;
    using System.IO;
    using System.Windows.Media.Imaging;
    ...
    PhotoChooserTask selectphoto = null;
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        selectphoto = new PhotoChooserTask();
        selectphoto.Completed += new EventHandler(selectphoto_Completed);
        selectphoto.Show();
    }
    void selectphoto_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            BinaryReader reader = new BinaryReader(e.ChosenPhoto);
            image1.Source = new BitmapImage(new Uri(e.OriginalFileName));
        }
    }

您可以尝试将UriKind从相对更改为绝对。如果我理解了您的代码,您将获得图片的绝对路径。

在我理解的代码中,您忘记了else情况下的。png。