private string MakeKey(FileSystemInfo finfo) { var fname = finfo.Name.ToLowerInvariant(); // Special case JPGs if (m_jpg_date_taken && Exif.IsJpgFile(finfo.FullName)) { using (var fs = new FileStream(finfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { var exif = Exif.Read(fs, false); if (exif != null && exif.HasTag(Exif.Tag.DateTimeOriginal)) { var dat = exif[Exif.Tag.DateTimeOriginal]; var ts = dat.AsString; return(ts + "-" + fname); } } } // Include the file size in the key if (finfo is FileInfo fi) { return(fi.Length + "-" + fname); } else { return(fname); } }
private static Task <Exif> GetExifFromImage(string file, Image image) { Exif exif = new Exif(); Parallel.ForEach(image.PropertyItems, Constants.ParallelOptions, current => { var previousPriority = Thread.CurrentThread.Priority; Thread.CurrentThread.Priority = ThreadPriority.Lowest; if (Constants.ExifData.ContainsKey(current.Id)) { exif.SetValue(Constants.ExifData[current.Id], current.Value); } //Reset previous priority of the TPL Thread Thread.CurrentThread.Priority = previousPriority; }); exif.HasBeenSet = true; Item item = CacheManager.Items[file]; item.Exif = exif; CacheManager.Items[file] = item; return(Task.FromResult(exif)); }
static void Main(string[] args) { Console.WriteLine("Enter path to a JPEG or TIFF file:"); PhpArray exif = Exif.read_exif_data(new PhpBytes(Console.ReadLine())); if (exif != null) { foreach (KeyValuePair <PHP.Core.IntStringKey, object> section in exif) { PhpArray array = section.Value as PhpArray; if (array != null) { foreach (KeyValuePair <PHP.Core.IntStringKey, object> entry in array) { Console.WriteLine("{0}.{1}: {2}", section.Key.Object, entry.Key.Object, entry.Value); } } else { Console.WriteLine("{0}: {1}", section.Key.Object, section.Value); } } } else { Console.WriteLine("Error reading EXIF headers from the file."); } Console.ReadLine(); }
public Dictionary <string, object> EXIF() { Dictionary <string, object> Exif; long exifOffset; if (!offsets.TryGetValue("exifIFD", out exifOffset)) { return(null); } Exif = extractTags(exifOffset, tags["exif"]); // fix formatting of some tags object ExifVersion; if (Exif.TryGetValue("ExifVersion", out ExifVersion)) { if (ExifVersion is string[]) { string exifVersion = ""; for (int i = 0; i < ((string[])ExifVersion).Length; i++) { exifVersion += (char)Convert.ToInt32(((string[])ExifVersion)[i]); } Exif["ExifVersion"] = exifVersion; } } return(Exif); }
public void CamereLensId(List<Camera> L1,List<Lens>L2,Exif check) { int index = L1.FindIndex(item => item.CameraID == check.Camera); if (index == 0) { // element not exists, do what you need L1.Add(new Camera { CameraID = check.Camera, CamCount = 1 }); } else { foreach (var cc in L1.Where(x => x.CameraID == check.Camera)) cc.CamCount++; } int index2 = L2.FindIndex(item => item.LensID == check.Lens); if (index2 == 0) { // element not exists, do what you need L2.Add(new Lens { LensID = check.Lens, LensCount = 1 }); } else { foreach (var lc in L2.Where(x => x.LensID == check.Lens)) lc.LensCount++; } }
internal void GetMetaData(string srcPath) { SuspendLayout(); lastSrcFilePath = srcPath; exif = new Exif(); alResults = exif.GetExif(srcPath); try { for (int idx = 0; idx < alResults.Count - 1; idx++) // (string row in alResults) { DataGridViewRow r = (DataGridViewRow)dataGridViewMetaData.Rows[0].Clone(); r.CreateCells(dataGridViewMetaData); r.Cells[0].Value = alResults[idx].ToString().Split(':')[0].ToString().Trim(); r.Cells[1].Value = alResults[idx].ToString().Split(':')[1].ToString().Trim(); UpdateGridView(r); } } catch (Exception ex) { string res = ex.Message; throw; } ResumeLayout(); }
public static Exif LoadFromImage(string fileName) { if (string.IsNullOrEmpty(fileName)) { return(null); } if (!System.IO.File.Exists(fileName)) { return(null); } Exif ex = new Exif(); using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fileName)) { foreach (System.Drawing.Imaging.PropertyItem pi in bmp.PropertyItems) { ex.SetParameter(new ExifParams() { Id = pi.Id, Data = pi.Value, DataLen = pi.Len, Type = (ExifType)pi.Type }); } return(ex); } return(null); }
// 用于保存执行了所有操作的图片 public void SavePhoto() { Bitmap image = null; Bitmap orgImage = null; try { // 读入原始图片及其原始格式 Cursor.Current = Cursors.WaitCursor; Global.Progress.Update(this, "Processing photo", 1, 2); // 确保图片不是只读的 if (FileManager.IsFileReadOnly(Photo.PhotoPath)) { throw new ApplicationException(string.Format("The photo \'{0}\' is read-only.", _photo.PhotoPath)); } // 创建可被保存的图片(原始图片的拷贝),保存原始图片知道我们将操作执行于新图片之上 // 然后使用原始图片来拷贝exif信息 orgImage = new Bitmap(_photo.PhotoPath); // 需要拷贝以便覆写原始图片 image = new Bitmap(orgImage); // 存储此图片的格式,用于后面的保存 ImageFormat format = orgImage.RawFormat; Global.Progress.Complete(this); Cursor.Current = Cursors.Default; // 在图片上执行所有的操作 OptimizeActions optimize = new OptimizeActions(); optimize.Apply(ref image, 0.0F); // 在保存前拷贝exif信息 if (Global.Settings.GetBool(SettingKey.MaintainExifInfo)) { Exif.Copy(orgImage, image); } // 在覆写前需要关闭原始图片 orgImage.Dispose(); orgImage = null; // 将图片存回文件系统 Global.Progress.Update(this, "Saving photo", 2, 2); image.Save(_photo.PhotoPath, format); OnNewPhoto(_photo.PhotoPath, image, format); } catch (Exception ex) { Global.DisplayError(string.Format("The file \'{0}\' could not be saved.", _photo.PhotoName), ex); } finally { // 消除操作 if (!(orgImage == null)) { orgImage.Dispose(); } if (!(image == null)) { image.Dispose(); } } // the crop area should be cleared Global.Progress.Complete(this); Cursor.Current = Cursors.Default; }
private Exif GetExif(int id) { using var connection = new SQLiteConnection(_connectionString); connection.Open(); var command = connection.CreateCommand(); command.CommandText = "SELECT id, manufacturer, model, focal_length, datetime_original FROM exif WHERE id=@id"; command.Parameters.AddWithValue("id", id); Exif exif = null; using var reader = command.ExecuteReader(); if (reader.Read()) { exif = new Exif { Id = reader.GetInt32(0), Manufacturer = reader.IsDBNull(2) ? null : reader.GetString(1), Model = reader.IsDBNull(1) ? null : reader.GetString(2) }; if (!reader.IsDBNull(3)) { exif.FocalLength = reader.GetInt32(3); } if (!reader.IsDBNull(4)) { exif.DateTimeOriginal = reader.GetDateTime(4); } } return(exif); }
public void MakeRequestTest() { string url = GetPolicy.MakeBaseUrl("qiniuphotos.qiniudn.com", "gogopher.jpg"); // TODO: 初始化为适当的值 string actual = Exif.MakeRequest(url); ExifRet ret = Exif.Call(actual); Assert.IsTrue(ret.OK, "MakeRequestTest Failure"); }
private void CopyMetadataTo(BitmapMetadata dst, Metadata src) { // ApplicationName CopyStringTagTo(dst, "ApplicationName", src, ExifTagID.Software); // Author PropertyItem[] authorsPI = src.GetExifValues(ExifTagID.Artist); if (authorsPI.Length > 0) { List <string> authors = new List <string>(); foreach (PropertyItem pi in authorsPI) { string author = Exif.DecodeAsciiValue(pi); authors.Add(author); } ReadOnlyCollection <string> authorsRO = new ReadOnlyCollection <string>(authors); dst.Author = authorsRO; } CopyStringTagTo(dst, "CameraManufacturer", src, ExifTagID.Make); CopyStringTagTo(dst, "CameraModel", src, ExifTagID.Model); CopyStringTagTo(dst, "Copyright", src, ExifTagID.Copyright); CopyStringTagTo(dst, "Title", src, ExifTagID.ImageDescription); PropertyItem[] dateTimePis = src.GetExifValues(ExifTagID.DateTime); if (dateTimePis.Length > 0) { string dateTime = Exif.DecodeAsciiValue(dateTimePis[0]); try { dst.DateTaken = dateTime; } catch (Exception) { try { string newDateTime = FixDateTimeString(dateTime); dst.DateTaken = newDateTime; } catch (Exception) { // *shrug* } } } }
public async Task MakeRequestTest() #endif { string url = GetPolicy.MakeBaseUrl("qiniuphotos.qiniudn.com", "gogopher.jpg"); // TODO: 初始化为适当的值 string actual = Exif.MakeRequest(url); #if NET20 || NET40 ExifRet ret = Exif.Call(actual); Assert.IsTrue(ret.OK, "MakeRequestTest Failure"); #else ExifRet ret = await Exif.CallAsync(actual); Assert.True(ret.OK, "MakeRequestTest Failure"); #endif }
public static Image 读取图片并根据Exif信息自动旋转(string 图像路径) { var img = 读取图像自文件(图像路径); try { var exif = new Exif(图像路径); var w = img.Width; var h = img.Height; 图像旋转(img, ref w, ref h, exif.orientationNumber); } catch (Exception e) { e.Trace(); } return(img); }
protected void btnNext_Click(object sender, EventArgs e) { if (tpuId > 0 && !string.IsNullOrEmpty(path)) { string imagePath = monitor.GetImgPathByTPUId(tpuId); string[] arrImgPath = imagePath.Split('|'); string thumbnailImgPath = string.Empty; for (int i = 0; i < arrImgPath.Length; i++) { var arrPath = arrImgPath[i].Split('.'); if (arrPath.Length > 1) { thumbnailImgPath += (arrPath[0] + "s." + arrPath[1] + "|"); } } if (hfImagePath.Value == "," || string.IsNullOrEmpty(hfImagePath.Value)) { imagePath = imagePath.Replace(path + "|", "").Replace(path, ""); thumbnailImgPath = thumbnailImgPath.Replace(path.Substring(0, path.LastIndexOf('.')) + "s" + path.Substring(path.LastIndexOf('.')) + "|", "").Replace(path.Substring(0, path.LastIndexOf('.')) + "s" + path.Substring(path.LastIndexOf('.')), ""); monitor.DeleteImageDetail(path); } else { imagePath = imagePath.Replace(path, path + "|" + hfImagePath.Value); thumbnailImgPath = thumbnailImgPath.Replace(path.Substring(0, path.LastIndexOf('.')) + "s" + path.Substring(path.LastIndexOf('.')), path.Substring(0, path.LastIndexOf('.')) + "s" + path.Substring(path.LastIndexOf('.')) + "|" + (hfImagePath.Value.Substring(0, path.LastIndexOf('.')) + "s" + hfImagePath.Value.Substring(path.LastIndexOf('.')))); string rootImage = ConfigurationManager.AppSettings["RootRadioSmartImage"] + System.IO.Path.DirectorySeparatorChar + hfImagePath.Value;//上传目录 Exif exif = new Exif(rootImage); string ShootPosition = ConvertDegreesToDigital(exif.GPSLongitude) + "," + ConvertDegreesToDigital(exif.GPSLatitude); if (!string.IsNullOrEmpty(exif.GPSLongitude) && !string.IsNullOrEmpty(exif.GPSLatitude)) { monitor.UpdateShootPosition(ShootPosition, tpuId); } string exportImgPath = monitor.GetIdByTPUId(tpuId) + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + hfImagePath.Value.Substring(hfImagePath.Value.LastIndexOf('.')); monitor.AddImageDetail(tpuId, hfImagePath.Value, hfImagePath.Value.Substring(0, hfImagePath.Value.LastIndexOf('.')) + "s" + hfImagePath.Value.Substring(hfImagePath.Value.LastIndexOf('.')), arrImgPath.Length, exportImgPath); } monitor.UpdateImagePath(imagePath.Trim('|'), thumbnailImgPath.Trim('|'), tpuId); Response.Redirect("ViewImage.aspx?tpuid=" + tpuId); } else { ScriptHelper.ShowCustomScript(this, "effect.Dialog.alert('操作出错!')"); Response.Redirect("ViewImage.aspx?tpuid=" + tpuId); } }
/// <summary> /// Extracts the exif save. /// </summary> /// <param name="stream">The stream.</param> /// <param name="momento">The momento.</param> /// <returns>DateTime.</returns> public DateTime?ExtractExifSave(Stream stream, Momento momento) { DateTime?date = null; using (stream) { System.Drawing.Image image = System.Drawing.Image.FromStream(stream); PropertyItem[] items = image.PropertyItems; if (items.Length > 0) { var exifs = new List <Exif>(); foreach (PropertyItem propertyItem in items) { //The below codes output funky strings that won't go into the database. string[] ignore = { "501b", "5091", "5090", "927c" }; string id = propertyItem.Id.ToString("x"); string value = Encoding.UTF8.GetString(propertyItem.Value); if (!ignore.Contains(id)) { var exif = new Exif { Momento = momento, Key = propertyItem.Id.ToString("x"), Type = propertyItem.Type, Value = string.IsNullOrWhiteSpace(value) ? string.Empty : value }; exifs.Add(exif); } date = GetDate(id, value, date); } SaveExifs(exifs); } } return(date); }
private void CopyStringTagTo(BitmapMetadata dst, string dstPropertyName, Metadata src, ExifTagID srcTagID) { PropertyItem[] pis = src.GetExifValues(srcTagID); if (pis.Length > 0) { PropertyInfo pi = dst.GetType().GetProperty(dstPropertyName); string piValue = Exif.DecodeAsciiValue(pis[0]); try { pi.SetValue(dst, piValue, null); } catch (Exception) { // *shrug* } } }
public Dictionary <string, object> EXIF() { Dictionary <string, object> Exif; long exifOffset; if (!offsets.TryGetValue("exifIFD", out exifOffset)) { return(null); } Exif = extractTags(exifOffset, tags["exif"]); // fix formatting of some tags object ExifVersion; if (Exif.TryGetValue("ExifVersion", out ExifVersion)) { if (ExifVersion is string[]) { string exifVersion = ""; for (int i = 0; i < ((string[])ExifVersion).Length; i++) { exifVersion += (char)Convert.ToInt32(((string[])ExifVersion)[i]); } Exif["ExifVersion"] = exifVersion; } } // store the keys separately (required for JS part to iterate over) if (!Exif.ContainsKey("keys")) { string[] keys = new string[Exif.Keys.Count]; Exif.Keys.CopyTo(keys, 0); Exif.Add("keys", keys); } return(Exif); }
/// <summary>Create a key for 'fi'</summary> public static string MakeKey(FileInfo fi) { // Generate a key for the file var fname = fi.Name.ToLowerInvariant(); // Special case JPGs if (Exif.IsJpgFile(fi.FullName)) { using (var fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { var exif = Exif.Read(fs, false); if (exif != null && exif.HasTag(Exif.Tag.DateTimeOriginal)) { var dat = exif[Exif.Tag.DateTimeOriginal]; var ts = dat.AsString; return(ts + "-" + fname); } } } // Include the file size in the key return(fi.Length + "-" + fname); }
public override int Run() { try { if (!Exif.IsJpgFile(m_jpg_filepath)) { Console.WriteLine($" {m_jpg_filepath} - Not a valid JPG file"); return(1); } var exif = Exif.Load(m_jpg_filepath); foreach (var tag in exif.Tags) { var field = exif[tag]; Console.WriteLine(field.ToString()); } return(0); } catch (Exception ex) { Console.WriteLine($" Error: {ex.Message}"); return(-1); } }
private void CopyMetadataTo(Metadata dst, BitmapMetadata src) { dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Software, src.ApplicationName) }); ReadOnlyCollection <string> authors = src.Author; if (authors != null) { List <PropertyItem> piAuthors = new List <PropertyItem>(); foreach (string author in authors) { PropertyItem piAuthor = Exif.CreateAscii(ExifTagID.Artist, author); piAuthors.Add(piAuthor); } dst.AddExifValues(piAuthors.ToArray()); } dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Make, src.CameraManufacturer) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Model, src.CameraModel) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Copyright, src.Copyright) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.DateTime, src.DateTaken) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.ImageDescription, src.Title) }); }
// 在列表中选中的缩略图上执行参数中指定的旋转操作 private void RotateThumbnails(ActionItem actionItem) { Bitmap image = null; Bitmap orgImage = null; try { int pos = 1; // 要显示的状态栏信息 string message = string.Format("Processing photo{0}", ((listView.SelectedItems.Count == 1) ? "" : "s")); // 将指定的操作实施到选定的图片上 foreach (ListViewItem item in listView.SelectedItems) { Global.Progress.Update(this, message, pos, listView.SelectedItems.Count); pos++; // 确定如何旋转图片 RotateFlipType flipType = RotateFlipType.RotateNoneFlipNone; switch (actionItem.Action) { case PhotoAction.RotateLeft: flipType = RotateFlipType.Rotate270FlipNone; break; case PhotoAction.RotateRight: flipType = RotateFlipType.Rotate90FlipNone; break; case PhotoAction.FlipHorizontal: flipType = RotateFlipType.RotateNoneFlipX; break; case PhotoAction.FlipVertical: flipType = RotateFlipType.RotateNoneFlipY; break; } // 获取图片对象 Photo photo = (Photo)item.Tag; //// 确保图片不处于只读模式 //if (FileManager.IsFileReadOnly(photo.PhotoPath)) //{ // throw new ApplicationException(string.Format("The photo \'{0}\' is read-only.", photo.PhotoPath)); //} // 创建两个图片对象,image用于在图片上执行操作并保存 // orgImage用作原始图片的副本,用于在对image执行操作后其拷贝exif信息 orgImage = new Bitmap(photo.Thumbnail, photo.Thumbnail.Width, photo.Thumbnail.Height); // 需要做一个拷贝以便覆写源图片 image = new Bitmap(orgImage); // 保留图片的格式信息,用于后面的保存操作 ImageFormat format = orgImage.RawFormat; // 旋转图片 image.RotateFlip(flipType); // 在保存前拷贝exif信息 if (Global.Settings.GetBool(SettingKey.MaintainExifInfo)) { Exif.Copy(orgImage, image); } // 需要在覆写前关闭原始图片 orgImage.Dispose(); orgImage = null; //保存图片 //image.Save(photo.PhotoPath, format); photo.Thumbnail = image; image.Dispose(); image = null; } } catch { // 执行清除操作 if (!(orgImage == null)) { orgImage.Dispose(); } if (!(image == null)) { image.Dispose(); } //Global.DisplayError("The photo could not be rotated.", ex); } }
/// <summary>TBD</summary> /// <param name="imageTagCollection">TBD</param> /// <param name="hasLatLong">TBD</param> /// <returns>TBD</returns> private static decimal[] InnerGetImageLatLong(Exif.ExifTagCollection imageTagCollection, out bool hasLatLong) { decimal[] imageLatLong = new decimal[2]; hasLatLong = false; Hashtable latLongValues = new Hashtable(); foreach (Exif.ExifTag tag in imageTagCollection) { if ((string.Compare(tag.FieldName, "GPSLATITUDEREF", true) == 0) || (string.Compare(tag.FieldName, "GPSLATITUDE", true) == 0) || (string.Compare(tag.FieldName, "GPSLONGITUDEREF", true) == 0) || (string.Compare(tag.FieldName, "GPSLONGITUDE", true) == 0)) { latLongValues.Add(tag.FieldName.ToUpper(), tag.Value); hasLatLong = true; } } if (hasLatLong) { //Lat first imageLatLong[0] = ConvertToDecimalDegrees(Convert.ToString(latLongValues["GPSLATITUDE"]), Convert.ToString(latLongValues["GPSLATITUDEREF"]).ToUpper().Contains("SOUTH")); //Then Long imageLatLong[1] = ConvertToDecimalDegrees(Convert.ToString(latLongValues["GPSLONGITUDE"]), Convert.ToString(latLongValues["GPSLONGITUDEREF"]).ToUpper().Contains("WEST")); } else { imageLatLong[0] = -1; imageLatLong[1] = -1; } return imageLatLong; }
public static Exif ExifAnalyse(Stream stream) { Exif exif = new Exif(); try { // ����һ��ͼƬ��ʵ�� /****************************************************** * ���ܳ��� * * System.ArgumentException: * * ����û����Ч��ͼ���ʽ- �� -stream Ϊ null�� * * modify:����try{}catch{}��myxbing,2007-8-31 * *****************************************************/ Image MyImage = Image.FromStream(stream); // ����һ�������������洢ͼ�������������ID int[] MyPropertyIdList = MyImage.PropertyIdList; //����һ�����ͼ�����������ʵ�� PropertyItem[] MyPropertyItemList = new PropertyItem[MyPropertyIdList.Length]; // ASCII���� System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); int index = 0; int MyPropertyIdListCount = MyPropertyIdList.Length; if (MyPropertyIdListCount != 0) { foreach (int MyPropertyId in MyPropertyIdList) { MyPropertyItemList[index] = MyImage.GetPropertyItem(MyPropertyId); #region ��ʼ��������ֵ string myPropertyIdString = MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x"); switch (myPropertyIdString) { case "131": exif.BySoftware = asciiEncoding.GetString(MyPropertyItemList[index].Value); break; case "132": exif.DateTime = asciiEncoding.GetString(MyPropertyItemList[index].Value); break; case "829a": exif.ExposureTime = GetExposureTimeValue(MyPropertyItemList[index].Value); break; case "829d": exif.FNumber = GetFnumberValue(MyPropertyItemList[index].Value); break; case "9209": //����� exif.Flash = BoolToEXIFValue(MyPropertyItemList[index].Value); break; case "8827": exif.IsoSpeed = "ISO-" + ShortToEXIFValue(MyPropertyItemList[index].Value); break; case "10f": exif.EquipmentMake = asciiEncoding.GetString(MyPropertyItemList[index].Value); break; } #endregion index++; } } exif.XResolution = MyImage.HorizontalResolution.ToString() + "DPI"; exif.YResolution = MyImage.VerticalResolution.ToString() + "DPI"; exif.ImageHeight = MyImage.Height.ToString(); exif.ImageWidth = MyImage.Width.ToString(); MyImage.Dispose(); } catch { } return(exif); }
public static Exif SaveToSecureFile(Exif exif, string srcPath, string dstPath) { throw new NotImplementedException(); }
protected void btnNext_Click(object sender, EventArgs e) { if (tpId == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>effect.Dialog.alert('错误操作!');</script>"); return; } int userId = monitor.GetUserIdByCusId(base.Profile.CusId); //if (base.Profile.CustomerType == 2 && userId == 0) //{ // Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>effect.Dialog.alert('该账号未绑定微信!');</script>"); // return; //} string imagePath = hfImagePath.Value; if (imagePath == "," || string.IsNullOrEmpty(imagePath)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>effect.Dialog.alert('请上传图片文件!');</script>"); return; } string rootImage = ConfigurationManager.AppSettings["RootRadioSmartImage"];//上传目录 string[] imagePaths = hfImagePath.Value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string thumbnailImgPaths = string.Empty, thumbnailImgPath = string.Empty, ShootPosition = string.Empty; DateTime ShootDate = new DateTime(); DataTable dt; if (userId > 0) { dt = monitor.GetTaskProjectUserRelation(tpId, userId, Profile.CusId); } else { dt = monitor.GetTaskProjectUserRelation(tpId); } if (dt.Rows.Count > 0) { for (int i = 0; i < imagePaths.Length; i++) { Exif exif = new Exif(rootImage + System.IO.Path.DirectorySeparatorChar + imagePaths[i]); string[] dtParts = exif.DateTime.Split(new string[2] { " ", ":" }, StringSplitOptions.RemoveEmptyEntries); if (dtParts.Length > 0) { if (Convert.ToInt32(dtParts[0]) > 0) { //有拍照日期 ShootDate = new DateTime(Convert.ToInt32(dtParts[0]), Convert.ToInt32(dtParts[1]), Convert.ToInt32(dtParts[2]), Convert.ToInt32(dtParts[3]), Convert.ToInt32(dtParts[4]), Convert.ToInt32(dtParts[5]), DateTimeKind.Local); } } if (!string.IsNullOrEmpty(exif.GPSLongitude) && !string.IsNullOrEmpty(exif.GPSLatitude)) { ShootPosition = ConvertDegreesToDigital(exif.GPSLongitude) + "," + ConvertDegreesToDigital(exif.GPSLatitude); } var arrPath = imagePaths[i].Split('.'); if (arrPath.Length > 1) { thumbnailImgPath = arrPath[0] + "s." + arrPath[1]; string exportImgPath = monitor.GetIdByTPUId(ConvertHelper.GetInteger(dt.Rows[0]["TPUId"])) + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + imagePaths[i].Substring(imagePaths[i].LastIndexOf('.')); monitor.AddImageDetail(ConvertHelper.GetInteger(dt.Rows[0]["TPUId"]), imagePaths[i], thumbnailImgPath, i + 1, exportImgPath); thumbnailImgPaths += thumbnailImgPath + "|"; } } imagePath = imagePath.Trim('|'); thumbnailImgPaths = thumbnailImgPaths.Trim('|'); if (userId == 0) { userId = ConvertHelper.GetInteger(dt.Rows[0]["UserId"]); } imagePath += "|" + dt.Rows[0]["ImgPath"]; thumbnailImgPaths += "|" + dt.Rows[0]["ThumbnailImgPath"]; if (ShootDate.Year == 1) { ShootDate = ConvertHelper.GetDateTime(dt.Rows[0]["ShootTime"]).Year == 1 ? DateTime.Now : ConvertHelper.GetDateTime(dt.Rows[0]["ShootTime"]); } if (string.IsNullOrEmpty(ShootPosition)) { ShootPosition = dt.Rows[0]["ShootPosition"].ToString(); } monitor.SaveImagePath(tpId, userId, Profile.CusId, imagePath.Trim('|'), thumbnailImgPaths.Trim('|'), ShootDate, ShootPosition); monitor.UpdateAbnormalType(tpId, ConvertHelper.GetInteger(hfAbnormalType.Value)); } if (Profile.CustomerType == 1) { Response.Redirect("ViewPlan.aspx?tid=" + tid); } Response.Redirect(string.Format("MyTaskList.aspx?tid={0}&type={1}&name={2}", tid, type, name)); }
public static void SaveExif (string path, Exif.ExifData data) { f_save_jpeg_exif (path, data.Handle); }
public static PixbufOrientation GetOrientation (Exif.ExifData data) { PixbufOrientation orientation = PixbufOrientation.TopLeft; Exif.ExifEntry e = data.GetContents (Exif.Ifd.Zero).Lookup (Exif.Tag.Orientation); if (e != null) { ushort [] value = e.GetDataUShort (); orientation = (PixbufOrientation) value [0]; } return orientation; }
public static void SaveJpeg (Pixbuf pixbuf, string path, int quality, Exif.ExifData exif_data) { Pixbuf temp = null; if (pixbuf.HasAlpha) { temp = Flatten (pixbuf); pixbuf = temp; } // The DCF spec says thumbnails should be 160x120 always Pixbuf thumbnail = ScaleToAspect (pixbuf, 160, 120); byte [] thumb_data = Save (thumbnail, "jpeg", null, null); exif_data.Data = thumb_data; thumbnail.Dispose (); // Most of the things we will set will be in the 0th ifd Exif.ExifContent content = exif_data.GetContents (Exif.Ifd.Zero); // reset the orientation tag the default is top/left content.GetEntry (Exif.Tag.Orientation).Reset (); // set the write time in the datetime tag content.GetEntry (Exif.Tag.DateTime).Reset (); // set the software tag content.GetEntry (Exif.Tag.Software).SetData (FSpot.Defines.PACKAGE + " version " + FSpot.Defines.VERSION); byte [] data = exif_data.Save (); FPixbufJpegMarker [] marker = new FPixbufJpegMarker [0]; bool result = false; unsafe { if (data.Length > 0) { fixed (byte *p = data) { marker = new FPixbufJpegMarker [1]; marker [0].type = 0xe1; // APP1 marker marker [0].data = p; marker [0].length = data.Length; result = f_pixbuf_save_jpeg (pixbuf.Handle, path, quality, marker, marker.Length); } } else result = f_pixbuf_save_jpeg (pixbuf.Handle, path, quality, marker, marker.Length); } if (temp != null) temp.Dispose (); if (result == false) throw new System.Exception ("Error Saving File"); }
public static bool SaveToJson(Exif exif, string srcPath, string dstPath) { throw new NotImplementedException(); }
public static Gdk.Pixbuf GetThumbnail (Exif.ExifData data) { byte [] thumb_data = data.Data; if (thumb_data.Length > 0) { PixbufOrientation orientation = GetOrientation (data); using (MemoryStream mem = new MemoryStream (thumb_data)) { Gdk.Pixbuf thumb = new Gdk.Pixbuf (mem); Gdk.Pixbuf rotated = PixbufUtils.TransformOrientation (thumb, orientation); if (rotated != thumb) thumb.Dispose (); return rotated; } } return null; }
public Exif(KaitaiStream p__io, KaitaiStruct p__parent = null, Exif p__root = null) : base(p__io) { m_parent = p__parent; m_root = p__root ?? this; _read(); }
public void SetExif (Exif.ExifData value) { // Console.WriteLine ("before save"); byte [] raw_data = value.Save (); // Console.WriteLine ("saved"); Marker exif = new Marker (ExifSignature.Id, raw_data); // Console.WriteLine ("new"); Replace (ExifSignature, exif); // Console.WriteLine ("replaced"); }
public static Exif MergeExif(Exif firstKey, Exif secondKey) { throw new NotImplementedException(); }
public static bool SaveToImage(Exif exif, string fileName) { throw new NotImplementedException(); }
public ColorMap <ushort> DecodeMap(Stream stream, Exif _exif) { var exif = (PanasonicExif)_exif; stream.Seek(exif.RawOffset, SeekOrigin.Begin); int row, col, i, j, sh = 0; int[] pred = new int[2], nonz = new int[2]; var resultHeight = exif.ImageHeight; var resultWidth = exif.CropRight; var map = new ColorMap <ushort>(resultWidth, resultHeight, 12); int value; var bits = new PanasonicBitStream(stream); for (row = 0; row < exif.ImageHeight; row++) { var line = map.GetRow(row); for (col = 0; col < exif.ImageWidth; col++) { unchecked { i = col % 14; if (i == 0) { pred[0] = pred[1] = nonz[0] = nonz[1] = 0; } if (i % 3 == 2) { sh = 4 >> (3 - bits.Read(2)); } if (nonz[i & 1] != 0) { j = bits.Read(8); if (j != 0) { pred[i & 1] -= 0x80 << sh; if (pred[i & 1] < 0 || sh == 4) { pred[i & 1] &= ~(-1 << sh); } pred[i & 1] += j << sh; } } else { nonz[i & 1] = bits.Read(8); if (nonz[i & 1] != 0 || i > 11) { pred[i & 1] = nonz[i & 1] << 4 | bits.Read(4); } } if (col >= resultWidth) { continue; } value = pred[col & 1]; if (value > 4098) { throw new Exception("Decoding error"); } line.SetAndMoveNext((ushort)Math.Min(4095, value)); } } } return(map); }