0

I'm building an app that should- among other things, let the user capture a picture and then save the picture and other info (like location of where this picture was taken -using GPS of the phone and etc...) on a DataBase.

Im using a string to save the pictures to the DataBase. So far so good. My problem is that after the user has captured a picture I can not find the path of the picture anyWhere (in order to display it later to the user ) I know I can display the picture if I use a image and not a string but then I am not able to save it to the DB.

Also I used the picture string (which should be the path of the picture ) to be the primaryKey column in my table and if the string is null this will be a problem for sure.

After checking on the internet I found out that you cannot use the GeoCoordinateWatcher (for GPS) on the emulator so I had to use a random place. This led me into thinking that a picture taken by the emulator may not have a path??

Part of my code: (the Event of the camera and the bottun that saves everyting to DB)

   void c_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            MessageBox.Show(e.ChosenPhoto.Length.ToString());


            //Code to display the photo on the page in an image control named myImage.
            BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);
            myImage.Source = bmp;//display the picture right after taking it. before saving to DB
            p.UrlImage = bmp.UriSource.AbsolutePath;//Do not Work!

        }
    }

    private void saveToDB_Click(object sender, RoutedEventArgs e)
    {

        p.Description = DesriptionList.SelectedValue.ToString();//description of the pic
        p.Date = DateTime.Today;//date picture taken

        GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher();
        var myPosition = myWatcher.Position;
        p.Location = myPosition.Location.Altitude+" "+myPosition.Location.Latitude;//do not work with emulator
        p.Location = "Some Where Over The Rainbow";
        MainPage.m._bl.addPic(p);//add pic to DB
        MessageBox.Show("Added Successfully! :)");
        NavigationService.Navigate(new Uri(@"/Intro.xaml", UriKind.Relative));//go to another page
    }
}

my class:

  [Table]
public class Picture
{
    public Picture()
    {

    }

    public Picture(string l, string d, string url, DateTime da)
    {
        Location = l;
        Description = d;
        UrlImage = url;
        Date = da;
    }
    string location;

    [Column]
    public string Location
    {
        get { return location; }
        set { location = value; }
    }
    string urlImage;

    [Column (IsPrimaryKey=true)]
    public string UrlImage
    {
        get { return urlImage; }
        set { urlImage = value; }
    }
    DateTime date;
    [Column]
    public DateTime Date
    {
        get { return date; }
        set { date = value; }
    }
    string description;
    [Column]
    public string Description
    {
        get { return description; }
        set { description = value; }
    }
}

}

Anyway- I would like to know if I can get the path in some way... And also- if I cant get the path- does Windows have a "Better" emulator? this emulator cant do much and this is quite annoying giving the fact I dont have a WP to check my apps on.. Thanks!

4

1 に答える 1