gpt4 book ai didi

c# - 使用 WriteImageToSavedPhotosAlbum 时未保存 Gps exif 数据

转载 作者:行者123 更新时间:2023-11-30 22:26:26 25 4
gpt4 key购买 nike

基本上我使用的示例代码来自 http://docs.xamarin.com/ios/recipes/Media/Video_and_Photos/Save_Photo_to_Album_with_Metadata

当我拍照并检查文件的 exif 数据时(通过 http://exifdata.com/ 或设备上的 Exif-Wizard),我注意到 exif 数据不包含 GPS 信息,所以我手动收集位置信息、格式它,并将其添加到字典中,并将其包含在元字典中,如下所示。

btnCamera.Clicked += delegate {
TweetStation.Camera.TakePicture (this, (obj) => {
var photo = obj.ValueForKey (new NSString ("UIImagePickerControllerOriginalImage")) as UIImage;
var meta = obj.ValueForKey (new NSString ("UIImagePickerControllerMediaMetadata")) as NSMutableDictionary;

var gpsDict = new NSMutableDictionary ();

...

gpsDict.SetValueForKey (NSObject.FromObject (GpsLong), new NSString ("GPSLongitude"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLongRef), new NSString ("GPSLongitudeRef"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLat), new NSString ("GPSLatitude"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLatRef), new NSString ("GPSLatitudeRef"));
gpsDict.SetValueForKey (NSObject.FromObject (DateTime.UtcNow.ToString ("HH:MM:ss.ff")), new NSString ("GPSTimeStamp"));

meta.SetValueForKey (gpsDict, new NSString ("{GPS}"));

Console.WriteLine (meta.Description);

ALAssetsLibrary library = new ALAssetsLibrary ();
library.WriteImageToSavedPhotosAlbum (photo.CGImage, meta, (assetUrl, error) => {

if (error != null) {
Console.WriteLine ("error: "+ error.ToString ());
}
):

问题是,这似乎不起作用,if (error != null) {Console.WriteLine (error.ToString ());} 没有打印任何问题,并且在Console.WriteLine(meta.Description);输出如下

{
DPIHeight = 72;
DPIWidth = 72;
Orientation = 6;
"{Exif}" = {
ApertureValue = "2.970853654340484";
BrightnessValue = "1.87496238139573";
ColorSpace = 1;
DateTimeDigitized = "2012:08:02 17:12:42";
DateTimeOriginal = "2012:08:02 17:12:42";
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.06666666666666667";
FNumber = "2.8";
Flash = 24;
FocalLength = "3.85";
ISOSpeedRatings = (
160
);
MeteringMode = 5;
PixelXDimension = 2592;
PixelYDimension = 1936;
SceneType = 1;
SensingMethod = 2;
Sharpness = 2;
ShutterSpeedValue = "3.911199862602335";
SubjectArea = (
1295,
967,
699,
696
);
WhiteBalance = 0;
};
"{GPS}" = {
GPSLatitude = "30.35974270979283";
GPSLatitudeRef = N;
GPSLongitude = "91.13930279830274";
GPSLongitudeRef = W;
GPSTimeStamp = "22:08:44.66";
};
"{TIFF}" = {
DateTime = "2012:08:02 17:12:42";
Make = Apple;
Model = "iPhone 4";
Software = "5.0.1";
XResolution = 72;
YResolution = 72;
};
}

显示 GPS 数据。

所以,我很好奇我做错了什么,我对 monotouch(也是 mac)很陌生,所以请原谅一般的 WTF'ery。

最佳答案

问题解决:

似乎问题是我的 Exif Gps 数据 block 不正确,我使用了错误的名称,并且 block 不完整,正在更改

gpsDict.SetValueForKey (NSObject.FromObject (GpsLong), new NSString ("GPSLongitude"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLongRef), new NSString ("GPSLongitudeRef"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLat), new NSString ("GPSLatitude"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLatRef), new NSString ("GPSLatitudeRef"));
gpsDict.SetValueForKey (NSObject.FromObject (DateTime.UtcNow.ToString ("HH:MM:ss.ff")), new NSString ("GPSTimeStamp"));

gpsDict.SetValueForKey(NSObject.FromObject(GpsAltitude),new NSString("Altitude"));
gpsDict.SetValueForKey(NSObject.FromObject(GpsAltitudeRef),new NSString("AltitudeRef"));

gpsDict.SetValueForKey(NSObject.FromObject(GpsImgDirection),new NSString("ImgDirection"));
gpsDict.SetValueForKey(NSObject.FromObject(GpsImgDirectionRef),new NSString("ImgDirectionRef"));

gpsDict.SetValueForKey (NSObject.FromObject (GpsLong), new NSString ("Longitude"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLongRef), new NSString ("LongitudeRef"));

gpsDict.SetValueForKey (NSObject.FromObject (GpsLat), new NSString ("Latitude"));
gpsDict.SetValueForKey (NSObject.FromObject (GpsLatRef), new NSString ("LatitudeRef"));

gpsDict.SetValueForKey (NSObject.FromObject (DateTime.UtcNow.ToString ("HH:MM:ss.ff")), new NSString ("TimeStamp"));

主要的变化是从所有标签名称中删除了 GPS 前缀,并添加了高度标签。

GPS exif block 应该如下所示

"{GPS}" =     {
Altitude = "14.9281";
AltitudeRef = 0;
ImgDirection = "107.4554";
ImgDirectionRef = T;
Latitude = "30.35514548114219";
LatitudeRef = N;
Longitude = "91.13394105024713";
LongitudeRef = W;
TimeStamp = "15:08:57.93";
};

关于c# - 使用 WriteImageToSavedPhotosAlbum 时未保存 Gps exif 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11787282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com