private async Task <bool> downloadPoiImgAsync(PoiApiRequest api, ViewPoi viewPoi) { bool result = false; if (!string.IsNullOrEmpty(viewPoi.ImgFilename)) { string pathToImg = Path.Combine(ImagePathManager.GetPicturesDirectory(), viewPoi.ImgFilename); string mapMarkerPreviewFilename = "map_" + viewPoi.ImgFilename; string pathToImgMarker = Path.Combine(ImagePathManager.GetPicturesDirectory(), mapMarkerPreviewFilename); if (!File.Exists(pathToImg) && (!string.IsNullOrEmpty(viewPoi.ImgFilename))) { result = await api.DownloadImg(viewPoi.Id, pathToImg); } if (!File.Exists(pathToImgMarker) && File.Exists(pathToImg)) { int sizeMarkerDivider = 3;//примерный делитель для получения более менее видимого маркера int sizeMarker = Convert.ToInt32(DeviceSize.FullScreenHeight / sizeMarkerDivider); ImagePreviewManager preview = new ImagePreviewManager(); preview.PreviewHeight = sizeMarker; preview.PreviewWidth = sizeMarker; preview.PreviewQuality = 30; preview.CreateImagePreview(ImagePathManager.GetPicturesDirectory(), viewPoi.ImgFilename, ImagePathManager.GetPicturesDirectory(), mapMarkerPreviewFilename); } } return(result); }
private async void takePhotoAsync(object obj) { await CrossMedia.Current.Initialize(); if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported) { if (string.IsNullOrEmpty(_vpoint.Id)) { ApplyChanges(); } ImageManager imageManager = new ImageManager(); var takePhotoResult = await imageManager.TakePhotoAsync(_vpoint.Latitude, _vpoint.Longitude); if (takePhotoResult.result) { ImagePreviewManager preview = new ImagePreviewManager(); if (preview.CreateImagePreview(takePhotoResult.newMediaId)) { _vpoint.AddMediaItem(takePhotoResult.newMediaId, MediaObjectTypeEnum.Image); ApplyChanges(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Images")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsOneImagesPresent")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("OneImagePath")); Analytics.TrackEvent("Media: photo taken"); } else { Analytics.TrackEvent("Media: new photo error create preview", new Dictionary <string, string> { { "mediaId", takePhotoResult.newMediaId } }); } } else { Analytics.TrackEvent("Media: new take photo error", new Dictionary <string, string> { { "mediaId", takePhotoResult.newMediaId } }); } } }
private async void takePhotoAsync() { await CrossMedia.Current.Initialize(); if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported) { if (string.IsNullOrEmpty(_vpoint.Id)) { _vpoint.Version++; _vpoint.Save(); } string mediaId = Guid.NewGuid().ToString(); string photoName = ImagePathManager.GetMediaFilename(mediaId, MediaObjectTypeEnum.Image); string photoNamePreview = ImagePathManager.GetMediaFilename(mediaId, MediaObjectTypeEnum.Image, true); MediaFile file = null; PermissionManager permissions = new PermissionManager(); if (await permissions.PermissionGrantedAsync(Plugin.Permissions.Abstractions.Permission.Photos, CommonResource.RoutePoint_RightNeedToTakePhoto)) { try { file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { PhotoSize = PhotoSize.Large, Location = new Location() { Latitude = _vpoint.Latitude, Longitude = _vpoint.Longitude, Timestamp = DateTime.Now }, Directory = string.Empty, Name = photoName, SaveToAlbum = true, CompressionQuality = 30 }); } catch (Exception e) { HandleError.Process("RoutePoint", "TakePhoto", e, false); } } if (file != null) { FileInfo info = new FileInfo(file.Path); string imgPathToDirectory = info.DirectoryName; file.Dispose(); ImagePreviewManager preview = new ImagePreviewManager(); if (preview.CreateImagePreview(imgPathToDirectory, info.Name, imgPathToDirectory, photoNamePreview)) { _vpoint.AddMediaItem(mediaId, MediaObjectTypeEnum.Image); ApplyChanges(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Images")); Analytics.TrackEvent("Media: photo taken"); } else { Analytics.TrackEvent("Media: new photo error create preview", new Dictionary <string, string> { { "mediaId", mediaId } }); } } } }
private async void addPhotoAsync(object obj) { _vpoint.Version++; _vpoint.Save(); bool b = await CrossMedia.Current.Initialize(); if (CrossMedia.Current.IsPickPhotoSupported) { MediaFile photoPicked = null; PermissionManager permissions = new PermissionManager(); if (await permissions.PermissionGrantedAsync(Plugin.Permissions.Abstractions.Permission.Photos, CommonResource.RoutePoint_RightNeedToPickPhoto)) { try { photoPicked = await CrossMedia.Current.PickPhotoAsync(); } catch (Exception e) { photoPicked = null; HandleError.Process("RoutePoint", "AddPhoto", e, false); } } if (photoPicked != null) { string imgPathDirectory = ImagePathManager.GetPicturesDirectory(); string mediaId = Guid.NewGuid().ToString(); //используем метод создания превью для того, чтобы сделать основное фото из оригинального, но с уменьшенным качеством ImagePreviewManager resizedOriginal = new ImagePreviewManager(); resizedOriginal.PreviewHeight = 0; resizedOriginal.PreviewWidth = 0; resizedOriginal.PreviewQuality = 40; FileInfo originalFileInfo = new FileInfo(photoPicked.Path); if (resizedOriginal.CreateImagePreview(originalFileInfo.DirectoryName, originalFileInfo.Name, imgPathDirectory, ImagePathManager.GetMediaFilename(mediaId, MediaObjectTypeEnum.Image, false))) { ImagePreviewManager preview = new ImagePreviewManager(); if (preview.CreateImagePreview(originalFileInfo.DirectoryName, originalFileInfo.Name, imgPathDirectory, ImagePathManager.GetMediaFilename(mediaId, MediaObjectTypeEnum.Image, true))) { ExifManager exif = new ExifManager(); var coords = exif.GetCoordinates(photoPicked.Path); if ((coords.Latitude > 0 && coords.Longitude > 0) && await App.Current.MainPage.DisplayAlert(CommonResource.RoutePoint_GeotagsExists, CommonResource.RoutePoint_UseGeotagsForPoint, CommonResource.CommonMsg_Yes, CommonResource.CommonMsg_No)) { Latitude = coords.Latitude; Longitude = coords.Longitude; _vpoint.Address = string.Empty; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Latitude")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Longitude")); FillAddressByCoordinatesAsync(Latitude, Longitude); } _vpoint.AddMediaItem(mediaId, MediaObjectTypeEnum.Image); ApplyChanges(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Images")); Analytics.TrackEvent("Media: photo added"); } else { Analytics.TrackEvent("Media: add photo error create preview ", new Dictionary <string, string> { { "mediaId", mediaId } }); } } else { Analytics.TrackEvent("Media: error resize photo ", new Dictionary <string, string> { { "mediaId", mediaId } }); } } } }