0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GeoTag(GPS情報)をjpgファイルに設定/取得する

Last updated at Posted at 2019-02-27

もくじ
https://qiita.com/tera1707/items/4fda73d86eded283ec4f

GeoTag関連

準備

  • WPFアプリでUWPのAPIを使用するため、プロジェクトの参照に下記の追加必要

    • C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd

    • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll

  • usingを追加

    • using Windows.Devices.Geolocation; // BasicGeoposition、Geopointのため
    • using Windows.Storage.FileProperties; // GeotagHelperのため

コード

jpgファイルからGPS情報読み出し


            var filepath = FilePathBox.Text;
            var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(filepath);
            if (file != null)
            {
                var gps = await GeotagHelper.GetGeotagAsync(file);

                if (gps != null)
                {
                    MessageBox.Show("latitude : " + gps.Position.Latitude + "\r\nLongitude : " + gps.Position.Longitude);
                }
                else
                {
                    // gpsデータなし
                }
            }

jpgファイルにgps情報を書き込み

            var filepath = FilePathBox.Text;
            var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(filepath);
            if (file != null)
            {
                // GPS値作成
                BasicGeoposition bgps = new BasicGeoposition();
                bgps.Latitude = 48.0;
                bgps.Longitude = 2.0;
                bgps.Altitude = 1.0;

                // GPS値をGeopointにセット
                Geopoint gps = new Geopoint(bgps);

                // GPS値をjpgファイルに書き込み
                await GeotagHelper.SetGeotagAsync(file, gps);
            }

置き場所

参照

まず、WPFからUWPのAPIを使えるようにする
https://blog.okazuki.jp/entry/2018/03/29/101601

GEotagHelperクラス
https://docs.microsoft.com/en-us/uwp/api/windows.storage.fileproperties.geotaghelper

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?