private Placemark PlacemarkFromPicture(PictureMetaData pic) { if (pic.GpsLongitude == null || pic.GpsLatitude == null) { return(null); } Placemark p = new Placemark(); p.Name = pic.IptcObjectName; p.Description = pic.IptcCaption; p.Latitude = (double)pic.GpsLatitude.GetValue(pic.GpsLatitudeRef == "S"); p.Longitude = (double)pic.GpsLongitude.GetValue(pic.GpsLongitudeRef == "W"); p.Tilt = Settings.Default.KmzTilt; p.Heading = Settings.Default.KmzHeading; p.Range = Settings.Default.KmzRange; ImageResize.Dimensions d; if (pic.Image.Height > pic.Image.Width) { d = ImageResize.Dimensions.Height; } else { d = ImageResize.Dimensions.Width; } Image i = ImageResize.ConstrainProportions(pic.Image, Settings.Default.KmzPictureSize, d); p.SetImage(new FileInfo(pic.Filename).Name, i); return(p); }
public ExifGpsModel(PictureMetaData pmd) { if (pmd == null) { return; } this.latitudeRef = Util.unNull(pmd.GpsLatitudeRef); this.longitudeRef = Util.unNull(pmd.GpsLongitudeRef); this.altitudeRef = Util.unNull(pmd.GpsAltitudeRef); this.speedRef = Util.unNull(pmd.GpsSpeedRef); this.trackRef = Util.unNull(pmd.GpsTrackRef); this.imageDirectionRef = Util.unNull(pmd.GpsImgDirectionRef); this.latitude = pmd.GpsLatitude; this.longitude = pmd.GpsLongitude; this.altitude = pmd.GpsAltitude.GetValueOrDefault(); this.speed = pmd.GpsSpeed.GetValueOrDefault(); this.track = pmd.GpsTrack.GetValueOrDefault(); this.imageDirection = pmd.GpsImgDirection.GetValueOrDefault(); if (pmd.GpsDateTimeStamp.HasValue) { this.date = pmd.GpsDateTimeStamp.Value; } else { this.date = DateTime.MinValue; } }
private void ProcessSingleWorkers(List <ModelBase> models, BackgroundWorker backgroundWorker) { SingleFileWorkerBase[] workers = new SingleFileWorkerBase[models.Count]; int i = 0; foreach (ModelBase model in models) { workers[i++] = (SingleFileWorkerBase)GetWorkerInstanceForModel(model); } foreach (string file in files) { PictureMetaData pmd = new PictureMetaData(file); i = 0; bool changed = false; foreach (ModelBase model in models) { changed = changed | workers[i++].ProcessFileModelBase(pmd, model); finishedStatusItems++; backgroundWorker.ReportProgress((finishedStatusItems) * 100 / numberOfStatusItems); } if (changed) { pmd.SaveChanges(); } pmd.Close(); } finishedWorkItems += workers.Length; finishedStatusItems += workers.Length * files.Count; }
private void SaveMetaData(Picture picture, byte[] data) { var exifs = PictureInfo.ReadExifs(data); foreach (var exifsTag in exifs.Keys) { var tag = this.picShareContext.PicturesMetaDatas.SingleOrDefault(x => x.PictureId == picture.Id && x.Tag == exifsTag); if (tag != null) { continue; } tag = new PictureMetaData { PictureId = picture.Id, Tag = exifsTag, Value = exifs[exifsTag], }; this.picShareContext.PicturesMetaDatas.Add(tag); } this.picShareContext.SaveChanges(); }
private bool SaveToPicture(PictureMetaData pic, bool commit) { // todo: die worker und modelle können mehrfach verwendet werden! IptcWorker iptcWorker = new IptcWorker(); ExifGpsWorker exifGpsWorker = new ExifGpsWorker(); IptcModel iptcModel = iptcView.GetModel(); ExifGpsModel exifGpsModel = exifGpsView.GetModel(); bool somethingChanged = false; if (iptcWorker.ProcessFile(pic, iptcModel)) { somethingChanged = true; } if (exifGpsWorker.ProcessFile(pic, exifGpsModel)) { somethingChanged = true; } if (iptcModel.PendingUpdates) { iptcModel.UpdateSettings(); } if (somethingChanged && commit) { if (!pic.SaveChanges()) { return(this.ShowFileVanishedMsg(pic.Filename)); } } return(true); }
public KmzMakerForm(PictureMetaData currentPicture, string currentDirectory, GetAllFilesDelegate getAllFilesDelegate) : this() { this.currentPicture = currentPicture; this.getAllFilesDelegate = getAllFilesDelegate; if (currentPicture != null) { FileInfo fi = new FileInfo(currentPicture.Filename); this.txtKmzFile.Text = currentPicture.Filename.Substring(0, currentPicture.Filename.Length - fi.Extension.Length) + ".kmz"; this.txtName.Text = currentPicture.IptcObjectName; } else { if (currentDirectory != "" && !currentDirectory.StartsWith("::")) { DirectoryInfo di = new DirectoryInfo(currentDirectory); this.txtKmzFile.Text = di.FullName + ".kmz"; this.txtName.Text = di.Name; } this.radSelected.Checked = true; this.radOneFile.Enabled = false; } this.chkOpen.Checked = Settings.Default.KmzOpenFile; }
public PictureGpsOffsetDialog(PictureMetaData picture, DateTime firstTime, DateTime lastTime) { InitializeComponent(); this.Icon = Resources.PTS; if (picture != null) { this.pictureDisplay1.DisplayPicture(picture); this.timeExif.Value = picture.ExifOriginalDateTime.GetValueOrDefault(); this.timeGps.Value = this.timeExif.Value; this.textBox1.Visible = false; } else { this.timeExif.Enabled = this.timeGps.Enabled = false; dontUpdate = true; this.textBox1.Visible = true; this.pictureDisplay1.Visible = false; //TODO: text ausgeben } this.labGpsLogInfo.Text = string.Format(this.labGpsLogInfo.Text, firstTime, lastTime); }
public MassWorkingFile(string filename, bool caching) { this.caching = caching; this.filename = filename; this.picture = null; this.jobs = new List <Job>(); }
public void Close() { if (picture != null) { picture.Close(); picture = null; } }
public override bool ProcessFile(PictureMetaData pmd, IptcModel model) { if (model.PendingUpdates) { model.UpdatePicture(pmd); } return(model.PendingUpdates); }
public bool ProcessFile(PictureMetaData pmd) { if (pmd.ExifThumbnailOrientation != pmd.ExifImageOrientation) { pmd.RemoveExifThumbnailOrientation(); return(true); } return(false); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = (BackgroundWorker)sender; PluginWorker worker = new PluginWorker(); backgroundWorker.ReportProgress(0); List <string> filenames = this.GetAllFileList(this.processFilesInSubdirectories); int i = 0; foreach (string filename in filenames) { i++; PictureMetaData pmd; if (this.currentPicture != null && this.currentPicture.Filename == filename) { pmd = currentPicture; } else { if (File.Exists(filename)) { pmd = new PictureMetaData(filename); } else { backgroundWorker.ReportProgress(i * 100 / filenames.Count); continue; } } bool breakForeach = false; if (worker.ProcessFile(pmd, pluginView.GetModel())) { if (!pmd.SaveChanges()) { breakForeach = !this.ShowFileVanishedMsg(pmd.Filename); } } if (pmd != currentPicture) { pmd.Close(); } if (breakForeach) { break; } backgroundWorker.ReportProgress(i * 100 / filenames.Count); } }
//controller private void buttonSaveAll_Click(object sender, EventArgs e) { IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm(); List <string> filenames = this.GetAllFileList(this.chkSubdirs.Checked); PauseOtherWorker(); statusDisplay.WorkStart(filenames.Count); foreach (string filename in filenames) { PictureMetaData pmd; if (this.currentPicture != null && this.currentPicture.Filename == filename) { pmd = currentPicture; } else { if (File.Exists(filename)) { pmd = new PictureMetaData(filename); } else { continue; } } bool breakForeach = SaveToPicture(pmd, true) == false; if (pmd != currentPicture) { pmd.Close(); } if (breakForeach) { break; } statusDisplay.WorkNextPart(); } FireDataChanged(); statusDisplay.WorkFinished(); RestartOtherWorker(); }
void gpsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = (BackgroundWorker)sender; backgroundWorker.ReportProgress(0); GpsWorkerArguemnts args = (GpsWorkerArguemnts)e.Argument; List <string> filenames = this.GetAllFileList(false); // compute the timespan of all pictures DateTime firstPicture = new DateTime(4000, 1, 1); DateTime lastPicture = new DateTime(1, 1, 1); List <PictureMetaData> pictures = new List <PictureMetaData>(); int i = 0; foreach (string filename in filenames) { i++; PictureMetaData pmd; if (this.currentPicture != null && this.currentPicture.Filename == filename) { pmd = currentPicture; } else { pmd = new PictureMetaData(filename); } if (pmd.ExifOriginalDateTime.HasValue) { DateTime time = pmd.ExifOriginalDateTime.Value; if (time > lastPicture) { lastPicture = time; } if (time < firstPicture) { firstPicture = time; } pictures.Add(pmd); } backgroundWorker.ReportProgress(i * 100 / filenames.Count); } e.Result = new GpsWorkerArguemnts(args.log, firstPicture, lastPicture, pictures); }
public void UpdatePicture(PictureMetaData pmd) { if (this.currentPicture != null) { this.currentPicture.Close(); } this.currentPicture = pmd; foreach (IPictureDetailControllerBase c in this) { c.UpdatePicture(pmd); } }
private void RefreshFileInfo(FileInfo fi) { PictureMetaData pmd; if (fi == null) { pmd = null; } else { pmd = new PictureMetaData(fi.FullName); } this.displayControls.UpdatePicture(pmd); }
private bool SaveToPicture(PictureMetaData pic, bool commit) { // todo: die worker und modelle können mehrfach verwendet werden! ExifDateWorker worker = new ExifDateWorker(); ExifDateModel model = view.GetModel(); if (worker.ProcessFile(pic, model) && commit) { if (!pic.SaveChanges()) { return(this.ShowFileVanishedMsg(pic.Filename)); } } return(true); }
public IptcModel(PictureMetaData pmd) { if (pmd == null) { return; } this.headline = Util.unNull(pmd.IptcHeadline); this.caption = Util.unNull(pmd.IptcCaption); this.objectName = Util.unNull(pmd.IptcObjectName); this.copyright = Util.unNull(pmd.IptcCopyright); this.city = Util.unNull(pmd.IptcCity); this.sublocation = Util.unNull(pmd.IptcSubLocation); this.provinceState = Util.unNull(pmd.IptcProvinceState); this.countryName = Util.unNull(pmd.IptcCountryName); this.countryCode = Util.unNull(pmd.IptcCountryCode); if (pmd.ListByline().Count > 0) { this.author = pmd.ListByline()[0]; } if (pmd.ListWriter().Count > 0) { this.writer = pmd.ListWriter()[0]; } if (pmd.ListContact().Count > 0) { this.contact = pmd.ListContact()[0]; } if (pmd.IptcDateTimeCreated.HasValue) { this.created = pmd.IptcDateTimeCreated.Value; } else { this.created = DateTime.MinValue; } foreach (string s in pmd.ListKeyword()) { keywordsBold.Add(s); keywordsChecked.Add(s); } }
void saveToAllWorker_DoWork(object sender, DoWorkEventArgs e) { List <string> filenames = (List <string>)e.Argument; BackgroundWorker worker = (BackgroundWorker)sender; worker.ReportProgress(0); int i = 0; foreach (string filename in filenames) { i++; PictureMetaData pmd; if (this.currentPicture != null && this.currentPicture.Filename == filename) { pmd = currentPicture; } else { if (File.Exists(filename)) { pmd = new PictureMetaData(filename); } else { worker.ReportProgress(i * 100 / filenames.Count); continue; } } bool breakForeach = SaveToPicture(pmd, true) == false; if (pmd != currentPicture) { pmd.Close(); } if (breakForeach) { break; } worker.ReportProgress(i * 100 / filenames.Count); } }
public bool ProcessFile(PictureMetaData pmd) { if (pmd.ExifOriginalDateTime.HasValue) { string year = pmd.ExifOriginalDateTime.Value.Year.ToString(); if (pmd.ListKeyword().Contains(year)) { return(false); } pmd.AddKeyword(year); return(true); } return(false); }
private void UpdateGpsData(PictureMetaData picture, GpsLog log) { if (picture.ExifOriginalDateTime.HasValue) { GpsLogEntry entry = log.GetNearestEntry(picture.ExifOriginalDateTime.Value); if (entry != null) { picture.GpsLatitude = new GpsCoordinate(entry.Latitude); picture.GpsLongitude = new GpsCoordinate(entry.Longitude); picture.GpsLatitudeRef = entry.Latitude >= 0 ? "N" : "S"; picture.GpsLongitudeRef = entry.Longitude >= 0 ? "E" : "W"; picture.GpsDateTimeStamp = entry.Time; picture.SaveChanges(); } } }
private void RenameFiles(RenameModel model) { newFiles = new List <string>(); RenamerEngine renamer = new RenamerEngine(model.FilenamePattern.Contains("%#"), !model.FilenamePattern.Contains("%##")); files.Sort(); foreach (string filename in files) { // get the new name form the metadata PictureMetaData pmd = new PictureMetaData(filename); string newname = FileNameFormater.FormatFilename(pmd, model.FilenamePattern); newname = newname.Replace("%##", "%#"); pmd.Close(); if (newname != "") { // open a file info FileInfo fi = new FileInfo(filename); newname = fi.DirectoryName + "\\" + newname; // give the new name to the renamer renamer.AddNewRenameItem(fi, newname); } else { newFiles.Add(filename); } // next this.FireOneFileProcessed(); } // and now: do all the dirty working renamer.CopyMove(true); // create the list of new files foreach (string filename in renamer.GetAllNewFilenames()) { if (File.Exists(filename)) { newFiles.Add(filename); } } }
public override bool ProcessFile(PictureMetaData pmd, PluginModel model) { IPhotoTagStudioTaggingPlugin plugin; if (cache.ContainsKey(model.Plugin)) { plugin = cache[model.Plugin]; } else { plugin = PluginView.GetPlugin(model.Plugin); cache.Add(model.Plugin, plugin); } if (plugin != null) { return(plugin.ProcessFile(pmd)); } return(false); }
public void UpdatePicture(PictureMetaData picture) { isDataLoaded = false; if (this.currentPicture != null && picture != null && this.currentPicture.Filename == picture.Filename) { return; } this.currentPicture = picture; if (this.currentPicture == null) { this.ClearData(); } else { this.RefreshData(); } }
private Folder CreateFolder(DirectoryInfo directory) { Folder folder = new Folder(directory.Name); foreach (FileInfo fi in directory.GetFiles("*.jpg")) { PictureMetaData pmd = new PictureMetaData(fi.FullName); Placemark placemark = PlacemarkFromPicture(pmd); if (placemark != null) { folder.Placemarks.Add(placemark); } pmd.Close(); } foreach (DirectoryInfo di in directory.GetDirectories()) { folder.Folders.Add(CreateFolder(di)); } return(folder); }
public void ProcessJobs() { if (this.jobs.Count == 0) { return; } PictureMetaData pmd = this.MetaData; foreach (Job j in jobs) { if (j.RepeatableTag) { pmd.RemoveRepeatableAttribute(j.TagName, j.OldValue); if (j.NewValue != "") { pmd.AddRepeatableAttribute(j.TagName, j.NewValue); } } else { if (pmd.getStringAttribute(j.TagName) == j.OldValue) { pmd.setStringAttribute(j.TagName, j.NewValue); } } } pmd.SaveChanges(); if (!this.caching) { pmd.Close(); } this.jobs = new List <Job>(); }
public override bool ProcessFile(PictureMetaData pmd, ExifDateModel model) { if (!model.PendingUpdates) { return(false); } // get the base value DateTime date = DateTime.MinValue; switch (model.SourceField) { case ExifDateFields.ExifImageDateTime: if (pmd.ExifImageDateTime.HasValue) { date = pmd.ExifImageDateTime.Value; } break; case ExifDateFields.ExifPhotoDateTimeOriginal: if (pmd.ExifOriginalDateTime.HasValue) { date = pmd.ExifOriginalDateTime.Value; } break; case ExifDateFields.ExifPhotoDateTimeDigitized: if (pmd.ExifDigitizedDateTime.HasValue) { date = pmd.ExifDigitizedDateTime.Value; } break; case ExifDateFields.ExifGpsInfoDateTimeStamp: if (pmd.GpsDateTimeStamp.HasValue) { date = pmd.GpsDateTimeStamp.Value; } break; case ExifDateFields.IptcCreated: if (pmd.IptcDateTimeCreated.HasValue) { date = pmd.IptcDateTimeCreated.Value; } break; case ExifDateFields.None: date = model.CustomSource; break; } // add the offset if (date != DateTime.MinValue && model.SourceField != ExifDateFields.None) { date = date.Add(model.Offset); } // now wirte it back to the fileds DateTime?newValue = date == DateTime.MinValue ? null : new DateTime?(date); if ((model.TargetFields & ExifDateFields.ExifImageDateTime) > 0) { pmd.ExifImageDateTime = newValue; } if ((model.TargetFields & ExifDateFields.ExifPhotoDateTimeOriginal) > 0) { pmd.ExifOriginalDateTime = newValue; } if ((model.TargetFields & ExifDateFields.ExifPhotoDateTimeDigitized) > 0) { pmd.ExifDigitizedDateTime = newValue; } if ((model.TargetFields & ExifDateFields.ExifGpsInfoDateTimeStamp) > 0) { pmd.GpsDateTimeStamp = newValue; } if ((model.TargetFields & ExifDateFields.IptcCreated) > 0) { pmd.IptcDateTimeCreated = newValue; } return(true); }
public abstract bool ProcessFile(PictureMetaData pmd, MODEL model);
public override bool ProcessFileModelBase(PictureMetaData pmd, ModelBase model) { return(ProcessFile(pmd, model as MODEL)); }
public void UpdatePicture(PictureMetaData pic) { if (latitudeChecked) { if (latitudeRef != "") { pic.GpsLatitudeRef = latitudeRef; pic.GpsLatitude = latitude.Clone(); } else { pic.GpsLatitude = null; pic.GpsLatitudeRef = ""; } } if (longitudeChecked) { if (longitudeRef != "") { pic.GpsLongitudeRef = longitudeRef; pic.GpsLongitude = longitude.Clone(); } else { pic.GpsLongitude = null; pic.GpsLongitudeRef = ""; } } if (altitudeChecked) { if (altitudeRef != "") { pic.GpsAltitudeRef = altitudeRef; pic.GpsAltitude = altitude; } else { pic.GpsAltitudeRef = ""; pic.GpsAltitude = null; } } if (speedChecked) { if (speedRef != "") { pic.GpsSpeedRef = speedRef; pic.GpsSpeed = speed; } else { pic.GpsSpeedRef = ""; pic.GpsSpeed = null; } } if (trackChecked) { if (trackRef != "") { pic.GpsTrackRef = trackRef; pic.GpsTrack = track; } else { pic.GpsTrackRef = ""; pic.GpsTrack = null; } } if (imageDirectionChecked) { if (imageDirectionRef != "") { pic.GpsImgDirectionRef = imageDirectionRef; pic.GpsImgDirection = imageDirection; } else { pic.GpsImgDirectionRef = ""; pic.GpsImgDirection = null; } } if (dateChecked) { if (date != DateTime.MinValue) { pic.GpsDateTimeStamp = date; } else { pic.GpsDateTimeStamp = null; } } if (pic.GpsLongitude == null && pic.GpsLatitude == null && !pic.GpsAltitude.HasValue && !pic.GpsSpeed.HasValue && !pic.GpsTrack.HasValue && !pic.GpsImgDirection.HasValue) { pic.GpsDateTimeStamp = null; pic.GpsVersionIdRemove(); } else { pic.GpsVersioIdInit(); } }