2

基本的に、 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データを表示しています。

だから、私が間違っていることに興味があります.私はモノタッチ(Macも)に非常に慣れていないので、一般的なWTF'eryを許してください.

4

2 に答える 2

2

問題が解決しました:

問題は、Exif Gps Dataブロックが正しくなく、間違った名前を使用していて、ブロックが不完全で、変更されていることだったようです。

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プレフィックスがすべてのタグ名から削除され、高度タグが追加されたことです。

GPSexifブロックは次のようになります

"{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";
};
于 2012-08-03T15:36:38.200 に答える
1

また、参考までに、タイプミスを防ぐために、これらの文字列はCGImagePropertiesMonoTouchの列挙型として公開されています

// Add GPS metadata, using data in local variables GpsAltitude, GpsLat, GpsLong, etc
gpsDict.SetValueForKey(NSObject.FromObject(GpsAltitude), CGImageProperties.GPSAltitude);
gpsDict.SetValueForKey(NSObject.FromObject(GpsAltitudeRef), CGImageProperties.GPSAltitudeRef);

gpsDict.SetValueForKey(NSObject.FromObject(GpsImgDirection), CGImageProperties.GPSImgDirection);
gpsDict.SetValueForKey(NSObject.FromObject(GpsImgDirectionRef), CGImageProperties.GPSImgDirectionRef);

gpsDict.SetValueForKey (NSObject.FromObject (GpsLong), CGImageProperties.GPSLongitude);
gpsDict.SetValueForKey (NSObject.FromObject (GpsLongRef), CGImageProperties.GPSLongitudeRef);

gpsDict.SetValueForKey (NSObject.FromObject (GpsLat), CGImageProperties.GPSLatitude);
gpsDict.SetValueForKey (NSObject.FromObject (GpsLatRef),CGImageProperties.GPSLatitudeRef);

gpsDict.SetValueForKey (NSObject.FromObject (DateTime.UtcNow.ToString ("HH:MM:ss.ff")), CGImageProperties.GPSTimeStamp);

// Add the GPS data to the metadata
meta.SetValueForKey (gpsDict, CGImageProperties.GPSDictionary);
于 2012-09-03T00:37:50.833 に答える