我正在使用C#为Windows Phone 8.1 RT制作相机应用程序,并希望将GPS位置添加到刚刚拍摄的图片的元数据中。
从GPS读取位置数据不是问题。 从(在这种情况下)image.jpg中读取元数据不是问题。 然而,编写/编辑数据是因为某些字段是只读的。
拍照,然后保存:
public async void take_picture()
{
ImageEncodingProperties format = ImageEncodingProperties.CreateJpeg();
format.Width = resolutionwidth;
format.Height = resolutionheight;
var imageStream = new InMemoryRandomAccessStream();
await captureManager.CapturePhotoToStreamAsync(format, imageStream);
//some more code
StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync("nameofpicture.jpg", CreationCollisionOption.GenerateUniqueName);
var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite);
await RandomAccessStream.CopyAsync(imageStream, fileStream);
}
阅读元数据。 (这些属性现在为空,但可以从另一张图片中读取属性。)
private async void metaread_button_click(object sender, RoutedEventArgs e)
{
StorageFile file1 = await KnownFolders.PicturesLibrary.GetFileAsync("nameofpicture.jpg");
var fileprops = await file1.Properties.GetImagePropertiesAsync();
textblock1.Text = "manufacturer: " + fileprops.CameraManufacturer; //writable property
textblock2.Text = "model: " + fileprops.CameraModel; //writable property
textblock3.Text = "title: " + fileprops.Title; //writable property
textblock4.Text = "latitude: " + fileprops.Latitude; //readonly property
textblock5.Text = "longtitude: " + fileprops.Longitude; //readonly property
textblock6.Text = "orientation: " + fileprops.Orientation; //readonly property
}
修改可写元数据:
private async void metawrite_button_click(object sender, RoutedEventArgs e)
{
StorageFile file2 = await KnownFolders.PicturesLibrary.GetFileAsync("nameofpicture.jpg");
var fileprops = await file2.Properties.GetImagePropertiesAsync();
fileprops.Title = "picture by me";
await fileprops.SavePropertiesAsync();
}
问题:如何设置只读属性? " ImageEncodingProperties"设置图像的属性,但不设置文件。
答案 0 :(得分:0)
终于找到了答案。请参阅RD8388的回答。只需要将lat / long转换为Degree / Minute / Second格式。你不需要按照他的建议去评论经度分母。只需确保你的秒数(分子属性)除以分母落在预期的范围内。