2

説明:締め切りの 2 日前に、TakePicture メソッドで撮影した写真がジオロケーションを保存しないことを Stuart が確認し、確認しました。

WORKS:
1. 写真は TakePicture で撮影され、保存されます
2. 緯度と経度が検出され、各プラットフォーム
の実装に送信されます 3. 写真が実装に保存された後、fileName がコアから送信されます
4. プラットフォームの実装には Geo が含まれています画像へのタグ
付け 5. 画像のアップロードが機能し、ジオタグが送信されます

画像にジオタグを追加するコード:

Android(更新:動作中):

public bool SaveImageWithGpsTags(string fileName, double lat, double lng)
{
   var context = Mvx.Resolve<IMvxAndroidGlobals>().ApplicationContext;
   var fullPath = Path.Combine(context.FilesDir.Path, fileName);

   if (!File.Exists(fullPath)) return false;
   try
   {
       using (var ef = new ExifInterface(fullPath))
       {
          ef.SetAttribute(ExifInterface.TagGpsLatitude, Dec2Dms(lat));
          ef.SetAttribute(ExifInterface.TagGpsLongitude, Dec2Dms(lng));
          ef.SetAttribute(ExifInterface.TagGpsLatitudeRef, lat > 0 ? "N" : "S");
          ef.SetAttribute(ExifInterface.TagGpsLongitudeRef, lng > 0 ? "E" : "W");
          ef.SaveAttributes();
       }
   }
   catch (Exception e)
   {
       return false;
   }
}

static String Dec2Dms(double coord)
{
    coord = coord > 0 ? coord : -coord;  // -105.9876543 -> 105.9876543
    var sOut = string.Format("{0}/1,", ((int)coord));   // 105/1,
    coord = (coord % 1) * 60;         // .987654321 * 60 = 59.259258
    sOut = sOut + string.Format("{0}/1,", ((int)coord));   // 105/1,59/1,
    coord = (coord % 1) * 60000;             // .259258 * 60000 = 15555
    sOut = sOut + string.Format("{0}/1000,", ((int)coord));   // 105/1,59/1,15555/1000
    return sOut;
}

タッチ(更新:動作中):

   const string resScheme = "res:";
   var imagePath = fileName.StartsWith(resScheme) ? fileName.Substring(resScheme.Length) : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName);
   var originalImage = UIImage.FromFile(imagePath);
   var gpsDict = new NSMutableDictionary();
   var imageMetadata = new NSMutableDictionary();

   gpsDict.SetValueForKey(NSObject.FromObject(lng), new NSString("Longitude"));
   gpsDict.SetValueForKey(NSObject.FromObject(lng > 0 ? "E" : "W"), new NSString("LongitudeRef"));
   gpsDict.SetValueForKey(NSObject.FromObject(lat), new NSString("Latitude"));
   gpsDict.SetValueForKey(NSObject.FromObject(lat > 0 ? "N" : "S"), new NSString("LatitudeRef"));
   gpsDict.SetValueForKey(NSObject.FromObject(DateTime.UtcNow.ToString("HH:MM:ss.ff")), new NSString("TimeStamp"));
   imageMetadata.SetValueForKey (gpsDict as NSDictionary, MonoTouch.ImageIO.CGImageProperties.GPSDictionary);

   var imgSrc = CGImageSource.FromData (originalImage.AsJPEG ());
   var outImageData = new NSMutableData();

   using (
        var d = CGImageDestination.FromData(outImageData, imgSrc.TypeIdentifier, 1,
                new CGImageDestinationOptions()))
        {
            d.AddImage (imgSrc, imgSrc.ImageCount - 1, imageMetadata);
            d.Close();
        }
  NSError writeError;
  var imageSaved = outImageData.Save(imagePath, NSDataWritingOptions.Atomic, out writeError);



更新: (UPLOAD WORKS NOW!):
画像を送信するコードは次のとおりです。

if (client.DefaultRequestHeaders.CacheControl == null)
    client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue();

client.DefaultRequestHeaders.CacheControl.NoCache = true;
client.DefaultRequestHeaders.CacheControl.NoStore = true;

byte[] imageBytes;
var result = Mvx.Resolve<IMvxFileStore>().TryReadBinaryFile(imagePath, out imageBytes);
var fileContent = new ByteArrayContent(imageBytes,0,imageBytes.Count());
var fileName = NewGuid() + ".jpg";
const string reference = "picture"
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
    FileName = fileName,
    Name = reference,
};
content.Add(fileContent);
content.Add(new StringContent(Settings.UserId), "userid");
await client.PostAsync("SOME SERVER URL", content);
4

1 に答える 1

0

ソリューションに関心のあるすべての人は、質問自体の回答が更新されていることに気付くでしょう。

ごめんチーズバロン、知らなかった!

于 2014-02-19T11:15:30.390 に答える