I tried to use ExifInterface
to set Location of image like this:
public void Save(Bitmap bitmap, string filePath, GpsLocation location) { using(var stream = new MemoryStream()) { bitmap.Compress(Bitmap.CompressFormat.Jpeg, 50, stream); if (location.Longtitude != null) { ExifInterface newExif = new ExifInterface(filePath); newExif.SetAttribute(ExifInterface.TagGpsLongitudeRef, location.Latitude); newExif.SetAttribute(ExifInterface.TagGpsLongitudeRef, location.Longtitude); newExif.SaveAttributes(); } FileStorageHelper.WriteFile(filePath, Storage.External, stream.ToArray()); } }
But it doesn't work, the image detail doesn't contain Location properties. Any ideas about this?
You need to save the image to the file path before saving the attributes, so this should do it
public void Save(Bitmap bitmap, string filePath, GpsLocation location) { using (var stream = new MemoryStream()) { bitmap.Compress(Bitmap.CompressFormat.Jpeg, 50, stream); FileStorageHelper.WriteFile(filePath, Storage.External, stream.ToArray()); } if (location.Longtitude != null) { ExifInterface newExif = new ExifInterface(filePath); newExif.SetAttribute(ExifInterface.TagGpsLongitudeRef, location.Latitude); newExif.SetAttribute(ExifInterface.TagGpsLongitudeRef, location.Longtitude); newExif.SaveAttributes(); } }
Answers
You need to save the image to the file path before saving the attributes, so this should do it
It works for me, thanks @LasseMadsen