// GeoTag the given file
 private async void GeoTagImageFile(IStorageFile image)
 {
     if (_geo != null)
     {
         await GeotagHelper.SetGeotagFromGeolocatorAsync(image, _geo);
     }
 }
示例#2
0
        // CAPABILITY!!!!!!!
        private async void GetGeoData(StorageFile imageFile)
        {
            // <SnippetGetGeoData>
            Geopoint geoPoint = await GeotagHelper.GetGeotagAsync(imageFile);

            // </SnippetGetGeoData>
        }
示例#3
0
        public static async Task <List <LocationData> > GetPhotoInDevice()
        {
            List <LocationData>         mapPhotoIcons = new List <LocationData>();
            IReadOnlyList <StorageFile> photos        = await KnownFolders.CameraRoll.GetFilesAsync();

            for (int i = 0; i < photos.Count; i++)
            {
                Geopoint geopoint = await GeotagHelper.GetGeotagAsync(photos[i]);

                if (geopoint != null)
                {
                    //should use Thumbnail to reduce the size of images, otherwise low-end device will crashes
                    var fileStream = await photos[i].GetThumbnailAsync(ThumbnailMode.PicturesView);
                    var img        = new BitmapImage();
                    img.SetSource(fileStream);


                    mapPhotoIcons.Add(new LocationData
                    {
                        Position    = geopoint.Position,
                        DateCreated = photos[i].DateCreated,
                        ImageSource = img
                    });
                }
            }
            var retMapPhotos = mapPhotoIcons.OrderBy(x => x.DateCreated).ToList();

            return(retMapPhotos);
        }
        private async void SetGeotagFromGeolocatorButton_Click()
        {
            // Call RequestAccessAsync from the UI thread to get user permission on location usage.
            // Otherwise SetGeotagFromGeolocator will fail.
            GeolocationAccessStatus status = await Geolocator.RequestAccessAsync();

            if (status != GeolocationAccessStatus.Allowed)
            {
                rootPage.NotifyUser("Location access is not allowed", NotifyType.ErrorMessage);
                return;
            }

            Geolocator geolocator = new Geolocator();

            geolocator.DesiredAccuracy = PositionAccuracy.High;

            try
            {
                await GeotagHelper.SetGeotagFromGeolocatorAsync(file, geolocator);

                rootPage.NotifyUser("Geolocation set to current location", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                // File I/O errors are reported as exceptions.
                // AccessDeniedExcetion can be raised if the user revoked location access
                // after RequestAccessAsync completed.
                rootPage.NotifyUser("Exception: " + ex.Message, NotifyType.ErrorMessage);
            }
        }
        private async Task WriteImage()
        {
            if (currentImageIndex == -1)
            {
                return;
            }
            try
            {
                await CreateFolder();

                StorageFile outputFile = await projectFolder.CreateFileAsync(filesNames.ElementAt(currentImageIndex), CreationCollisionOption.ReplaceExisting);

                var stream = (await outputFile.OpenStreamForWriteAsync()).AsRandomAccessStream();

                Guid encoderId;
                if (filesNames.ElementAt(currentImageIndex).Contains(".jpg"))
                {
                    encoderId = Windows.Graphics.Imaging.BitmapEncoder.JpegEncoderId;
                }

                var inputStream = await files.ElementAt(currentImageIndex).OpenStreamForReadAsync();

                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(inputStream.AsRandomAccessStream());

                var           inputProperties = decoder.BitmapProperties;
                var           memStream       = new Windows.Storage.Streams.InMemoryRandomAccessStream();
                BitmapEncoder encoder2        = await BitmapEncoder.CreateForTranscodingAsync(memStream, decoder);

                WriteImageMetadata(encoder2, inputProperties);
                await encoder2.FlushAsync();

                memStream.Seek(0);
                stream.Seek(0);
                stream.Size = 0;
                await RandomAccessStream.CopyAsync(memStream, stream);

                memStream.Dispose();

                stream.Dispose();
                inputStream.Dispose();
                if (latitude.Text != null)
                {
                    await GeotagHelper.SetGeotagAsync(outputFile, myLocation);
                }
            }
            catch (Exception err)
            {
                switch (err.HResult)
                {
                case unchecked ((int)0x88982F41):    // WINCODEC_ERR_PROPERTYNOTSUPPORTED
                                                     // The file format does not support this property.
                    break;

                default:
                    break;
                }
            }
        }
示例#6
0
        private async void SetGeoDataFromGeolocator(StorageFile imageFile)
        {
            // <SnippetSetGeoDataFromGeolocator>
            var locator = new Geolocator();

            // Shows the user consent UI if needed
            var accessStatus = await Geolocator.RequestAccessAsync();

            if (accessStatus == GeolocationAccessStatus.Allowed)
            {
                await GeotagHelper.SetGeotagFromGeolocatorAsync(imageFile, locator);
            }
            // </SnippetSetGeoDataFromGeolocator>
        }
示例#7
0
        private async void SetGeoDataFromPoint(StorageFile imageFile)
        {
            // <SnippetSetGeoDataFromPoint>
            var point = new Geopoint(
                new BasicGeoposition
            {
                Latitude  = 48.8567,
                Longitude = 2.3508,
            });

            await GeotagHelper.SetGeotagAsync(imageFile, point);

            // </SnippetSetGeoDataFromPoint>
        }
        private async void GetGeotagButton_Click()
        {
            Geopoint geopoint = await GeotagHelper.GetGeotagAsync(file);

            if (geopoint != null)
            {
                rootPage.NotifyUser($"Latitude = {geopoint.Position.Latitude}, Longitude = {geopoint.Position.Longitude}", NotifyType.StatusMessage);
            }
            else
            {
                // File I/O errors are converted to "No information".
                rootPage.NotifyUser("No location information available", NotifyType.ErrorMessage);
            }
        }
        private async Task SetGeotagFromGeolocatorAsync()
        {
            try
            {
                StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(filename.Text);

                Geolocator geolocator = new Geolocator();
                geolocator.DesiredAccuracy = PositionAccuracy.High;

                await GeotagHelper.SetGeotagFromGeolocatorAsync(file, geolocator);

                LogStatus("SetGeotagFromGeolocatorAsync complete");
            }
            catch (Exception e)
            {
                LogError("Exception: " + e.Message);
            }
        }
示例#10
0
        /// <summary>
        /// 情報読み出し
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            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データなし
                }
            }
        }
示例#11
0
        /// <summary>
        /// 情報書き込み
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            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);
            }
        }
        private async Task SetGeotagAsync()
        {
            try
            {
                StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(filename.Text);

                BasicGeoposition position = new BasicGeoposition();
                position.Latitude  = 10.0; // Use latitude 10.0, longitude 20.0 as an example
                position.Longitude = 20.0;
                position.Altitude  = 0.0;
                Geopoint geopoint = new Geopoint(position);

                await GeotagHelper.SetGeotagAsync(file, geopoint);

                LogStatus("SetGeotagAsync complete");
            }
            catch (Exception e)
            {
                LogError("Exception: " + e.Message);
            }
        }
        private async Task GetGeotagAsync()
        {
            try
            {
                StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(filename.Text);

                Geopoint geopoint = await GeotagHelper.GetGeotagAsync(file);

                if (geopoint != null)
                {
                    LogStatus("GetGeotagAsync complete -" + " latitude: " + geopoint.Position.Latitude + " longitude: " + geopoint.Position.Longitude);
                }
                else
                {
                    LogStatus("GetGeotagAsync complete - location info not available");
                }
            }
            catch (Exception e)
            {
                LogError("Exception: " + e.Message);
            }
        }
示例#14
0
        /// <summary>
        /// 情報書き込み
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var cur              = Directory.GetCurrentDirectory(); // exeのあるディレクトリ
            var filepath         = cur + @"\ginga.bmp";             // 元の画像
            var filepath_out_jpg = cur + @"\ginga_out.jpg";         // jpgとして保存する画像
            var filepath_out_bmp = cur + @"\ginga_out_fake.jpg";    // bmpとして保存する画像

            using (var fs = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite))
                using (var bmp = new System.Drawing.Bitmap(fs))
                {
                    // 元の画像を、jpgとbmpで保存し分ける
                    bmp.Save(filepath_out_jpg, System.Drawing.Imaging.ImageFormat.Jpeg);
                    bmp.Save(filepath_out_bmp, System.Drawing.Imaging.ImageFormat.Bmp);
                }

            // GPS値作成
            BasicGeoposition bgps = new BasicGeoposition()
            {
                Latitude = 3.0, Longitude = 2.0, Altitude = 1.0
            };
            // GPS値をGeopointにセット
            Geopoint gps = new Geopoint(bgps);

            try
            {
                // GPS値をjpgファイルに書き込み
                var stjpg = await Windows.Storage.StorageFile.GetFileFromPathAsync(filepath_out_jpg);

                await GeotagHelper.SetGeotagAsync(stjpg, gps);// →こっちは問題なくgeotag付与できる

                var stbmp = await Windows.Storage.StorageFile.GetFileFromPathAsync(filepath_out_bmp);

                await GeotagHelper.SetGeotagAsync(stbmp, gps);// →こっちは、jpgではないのでgeotag付与時に例外発生
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private async void SetGeotagButton_Click()
        {
            // Set the approximate position of the observation deck of the Seattle Space Needle.
            BasicGeoposition position = new BasicGeoposition();

            position.Latitude  = 47.620491;
            position.Longitude = -122.349319;
            position.Altitude  = 158.12;
            Geopoint geopoint = new Geopoint(position);

            try
            {
                await GeotagHelper.SetGeotagAsync(file, geopoint);

                rootPage.NotifyUser("Geolocation set to Seattle Space Needle", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                // File I/O errors are reported as exceptions
                rootPage.NotifyUser("Exception: " + ex.Message, NotifyType.ErrorMessage);
            }
        }
示例#16
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter is Dictionary <string, string> )
            {
                var dic = e.Parameter as Dictionary <string, string>;
                imageName = dic["ImagePath"];
            }
            StorageFile sourcePhoto = await KnownFolders.CameraRoll.GetFileAsync(imageName);

            IRandomAccessStream stream = await sourcePhoto.OpenAsync(FileAccessMode.Read);

            Geopoint geopoint = await GeotagHelper.GetGeotagAsync(sourcePhoto);

            if (geopoint != null && geopoint.Position.Latitude != 0)
            {
                App.currentLocation.Position = geopoint.Position;
            }
            App.currentLocation.DateCreated = sourcePhoto.DateCreated;
            await LocationHelper.TryUpdateMissingLocationInfoAsync(App.currentLocation, null);

            locationName = App.currentLocation.Name;

            if (sourcePhoto != null)
            {
                var imgSource = new BitmapImage();
                imgSource.SetSource(stream);
                imageToPost.Source = imgSource;
            }
            if (locationName != null)
            {
                LocationNameTbl.Text = locationName;
            }
            else
            {
                LocationNameTbl.Text = "Unknown";
            }
            base.OnNavigatedTo(e);
        }