我正在构建一个应用程序,该应用程序应该 - 除其他外,让用户捕捉图片,然后保存图片和其他信息(如拍摄该图片的位置 - 使用手机的GPS等...)在数据库上。Windows Phone 7.1 - 保存相机拍摄的照片路径CapsureTask
使用字符串将图片保存到数据库。到现在为止还挺好。我的问题是,在用户捕获图片后,我无法在任何地方找到图片的路径(为了稍后向用户显示) 我知道如果使用图片而不是字符串,我可以显示图片但后来我无法将它保存到数据库。
此外,我用图片字符串(应该是图片的路径)作为我的表中的primaryKey列,如果字符串为null,这将是一个肯定的问题。
在互联网上检查后,我发现你不能在模拟器上使用GeoCoordinateWatcher(用于GPS),所以我必须使用随机的地方。 这使我认为模拟器拍摄的照片可能没有路径?我的代码
部分:
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
}
}
我的课(相机和保存everyting到DB的bottun的事件):
[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-我会想知道我能否以某种方式获得路径... 而且,如果我无法获得路径 - Windows是否具有“更好”模拟器? 这个模拟器不能做很多,这是相当恼人的事实,我没有一个WP来检查我的应用程序.. 谢谢!
非常感谢!:) – nati 2013-05-23 18:37:16