Windows Phone Picturebox

I am developing a Windows Phone 8.1 application in C #. I use the camera to take a picture. The image is saved on the device, and I'm trying to show it in the image. I tested it on an HTC phone and it worked well, but when I tried it on Nokia Lumia, the image will never load. Does anyone have an idea how to solve this?

Here is the code I sing to take a picture:

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

        }
    }

And this is the code where I am trying to upload an image.

    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;

        };

    }

PS

booting from local resources works fine on both phones, it’s just the “more” part of the problem that causes problems in Nokia.

+4
source share
3 answers

, , ( , 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));
        }
    }
+3

UriKind . , .

+2

As I understand it, the code you forgot .png otherwise.

0
source

Source: https://habr.com/ru/post/1543723/


All Articles