/// <summary> /// Exif情報に回転情報を保存 /// </summary> /// <param name="imgBmp"></param> /// <param name="orientation"></param> public static void SetExifOrientation(int moduleId, Bitmap imgBmp, short orientation) { int[] pils = imgBmp.PropertyIdList; //処理速度向上のため、PropertyIdListが3未満はJFIFとする if (pils.Length < 3) { return; } // Exif情報から回転情報を取得する(0x0112:回転情報) int index = Array.IndexOf(pils, (int)Exif.Orientation); try { if (index >= 0) { System.Drawing.Imaging.PropertyItem pi = imgBmp.PropertyItems[index]; if (pi.Len == 2) { pi.Value = BitConverter.GetBytes(orientation); imgBmp.SetPropertyItem(pi); //これを呼ばないと設定されないので要注意 } } } catch (Exception ex) { EventLog.EventLogWriter.Write(EventLog.Const.LogSourceName, ex, EventLogEntryType.Error, moduleId, EventLog.Const.ClassId.DataStore); } }
void ShowPicture() { string name = undoStack[current]; Despatch(delegate() { lblFolder.Text = Path.GetFileName(Path.GetDirectoryName(name)); lblDate.Text = new FileInfo(name).LastWriteTime.Date.ToString("Y"); lblName.Text = Path.GetFileNameWithoutExtension(name); if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = Image.FromFile(name); DateTime dateCreated = new FileInfo(name).LastWriteTime; // Get the Date Created property //System.Drawing.Imaging.PropertyItem propertyItem = image.GetPropertyItem( 0x132 ); System.Drawing.Imaging.PropertyItem propertyItem = pictureBox1.Image.PropertyItems.FirstOrDefault(i => i.Id == 0x132); if (propertyItem != null) { // Extract the property value as a String. System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); string text = encoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1); // Parse the date and time. System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture; dateCreated = DateTime.ParseExact(text, "yyyy:MM:d H:m:s", provider); } lblFolder.Text = Path.GetFileName(Path.GetDirectoryName(name)); lblDate.Text = dateCreated.Date.ToString("Y"); lblName.Text = Path.GetFileNameWithoutExtension(name); }); }
/// <summary> /// Exif情報から回転情報を取得 /// </summary> /// <param name="imgBmp">ビットマップクラス</param> /// <remarks> /// 1 不要(回転・反転なし) /// 2 水平方向に反転 /// 3 時計回りに180度回転 /// 4 垂直方向に反転 /// 5 水平方向に反転 + 時計回りに270度回転 /// 6 時計回りに90度回転 /// 7 水平方向に反転 + 時計回りに90度回転 /// 8 時計回りに270度回転 /// </remarks> /// <returns></returns> public static bool GetExifOrientation(int moduleId, Bitmap imgBmp, out short orientation) { // 初期値は「1 不要(回転・反転なし)」とする orientation = 1; bool ret = false; int[] pils = imgBmp.PropertyIdList; //処理速度向上のため、PropertyIdListが3未満はJFIFとする if (pils.Length < 3) { return(ret); } // Exif情報から回転情報を取得する(0x0112:回転情報) int index = Array.IndexOf(pils, (int)Exif.Orientation); try { if (index >= 0) { System.Drawing.Imaging.PropertyItem pi = imgBmp.PropertyItems[index]; if (pi.Len == 2) { orientation = (short)pi.Value[0]; ret = true; } } } catch (Exception ex) { EventLog.EventLogWriter.Write(EventLog.Const.LogSourceName, ex, EventLogEntryType.Error, moduleId, EventLog.Const.ClassId.DataStore); } return(ret); }
private static string getDateShooting(FileStream file) { string dateShooting = ""; // Init bitmap Bitmap btmFile = new Bitmap(file); // Get the metadata date taken try { System.Drawing.Imaging.PropertyItem pimPropertyDateTaken = btmFile.GetPropertyItem(36867); // Convert the value in utf8 dateShooting = Encoding.UTF8.GetString(pimPropertyDateTaken.Value); // Remove : dateShooting = dateShooting.Replace(":", ""); // Remove space dateShooting = dateShooting.Replace(" ", ""); // Remove /0 dateShooting = dateShooting.Replace("\0", ""); } catch (ArgumentException err) { dateShooting = ""; } // Close the btmFile btmFile.Dispose(); // Return the date return(dateShooting); }
protected override Document OnLoad(Stream input) { byte[] bytes = new byte[input.Length]; input.ProperRead(bytes, 0, (int)input.Length); Document doc = GetOrientedDocument(bytes, out ExifValueCollection exifMetadata); byte[] colorProfileBytes = WebPFile.GetColorProfileBytes(bytes); if (colorProfileBytes != null) { #if PDN_3_5_X System.Drawing.Imaging.PropertyItem colorProfileItem = PaintDotNet.SystemLayer.PdnGraphics.CreatePropertyItem(); colorProfileItem.Id = unchecked ((ushort)ExifTagID.IccProfileData); colorProfileItem.Type = (short)ExifTagType.Undefined; colorProfileItem.Len = colorProfileBytes.Length; colorProfileItem.Value = colorProfileBytes.CloneT(); doc.Metadata.AddExifValues(new System.Drawing.Imaging.PropertyItem[] { colorProfileItem }); #else doc.Metadata.AddExifPropertyItem(PaintDotNet.Imaging.ExifSection.Image, unchecked ((ushort)ExifTagID.IccProfileData), new PaintDotNet.Imaging.ExifValue(PaintDotNet.Imaging.ExifValueType.Undefined, colorProfileBytes.CloneT())); #endif } if (exifMetadata != null) { foreach (MetadataEntry entry in exifMetadata.Distinct()) { #if PDN_3_5_X System.Drawing.Imaging.PropertyItem propertyItem = entry.TryCreateGdipPropertyItem(); if (propertyItem != null) { doc.Metadata.AddExifValues(new System.Drawing.Imaging.PropertyItem[] { propertyItem }); } #else doc.Metadata.AddExifPropertyItem(entry.CreateExifPropertyItem()); #endif } } byte[] xmpBytes = WebPFile.GetXmpBytes(bytes); if (xmpBytes != null) { #if PDN_3_5_X doc.Metadata.SetUserValue(WebPMetadataNames.XMP, Convert.ToBase64String(xmpBytes, Base64FormattingOptions.None)); #else PaintDotNet.Imaging.XmpPacket xmpPacket = PaintDotNet.Imaging.XmpPacket.TryParse(xmpBytes); if (xmpPacket != null) { doc.Metadata.SetXmpPacket(xmpPacket); } #endif } return(doc); }
public static string GetCommentsFromPNG(this Bitmap bitmap) { //doesn't work for png System.Drawing.Imaging.PropertyItem prop = bitmap.GetPropertyItem(40094); string comment = Encoding.Unicode.GetString(prop.Value); return(comment); }
// // Sets specified property in raw form // // Property ID // Raw data // EXIF data type // Is recommended to use typed methods (like etc.) instead, when possible. // // [altair] 12.6.2004 Created // public void SetProperty(Int32 PID, byte[] Data, ExifDataTypes Type) { System.Drawing.Imaging.PropertyItem P = this._Image.PropertyItems[0]; P.Id = PID; P.Value = Data; P.Type = (Int16)Type; P.Len = Data.Length; this._Image.SetPropertyItem(P); }
/// <summary> /// Gets a .NET PropertyItem for this metadata tag. /// </summary> /// <returns>The .NET PropertyItem.</returns> public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem() { System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem(); item.Id = ID; item.Len = (int)Length; item.Type = (short)Type; FreeImage.CopyMemory(item.Value = new byte[item.Len], FreeImage.GetTagValue(tag), item.Len); return(item); }
//retrieves the datetime WITHOUT loading the whole image public static DateTime GetDateTakenFromImage(string path) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) using (System.Drawing.Image myImage = System.Drawing.Image.FromStream(fs, false, false)) { System.Drawing.Imaging.PropertyItem propItem = myImage.GetPropertyItem(36867); string dateTaken = r.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2); return(DateTime.Parse(dateTaken)); } }
/// <summary> /// Fix image orientation /// </summary> static System.Drawing.Image FixImageOrientation(string fileName) { System.Drawing.Image sysImage = System.Drawing.Image.FromFile(fileName, false); // fix orientation by EXIF rotation tag const int exifRotationTag = 0x0112; int[] propertyItemIDs = sysImage.PropertyIdList; int found = Array.BinarySearch(propertyItemIDs, 0, propertyItemIDs.Length, exifRotationTag); if (found > -1) { System.Drawing.Imaging.PropertyItem pi = sysImage.GetPropertyItem(exifRotationTag); int orientation = pi.Value[0]; switch (orientation) { case 2: sysImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); break; case 3: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); break; case 4: sysImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY); break; case 5: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipX); break; case 6: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); break; case 7: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipX); break; case 8: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone); break; default: break; } sysImage.RemovePropertyItem(0x0112); } return(sysImage); }
private string getUInt16Property(ref System.Drawing.Imaging.PropertyItem property) { int i = 0; string text = ""; while (i < property.Len) { text += System.BitConverter.ToUInt16(property.Value, i).ToString(); text += CultureStrings.MarkerWhiteSpace; i += 2; } return(text); }
private string getHexProperty(ref System.Drawing.Imaging.PropertyItem property) { int i = 0; string text = ""; while (i < property.Len) { text += property.Value[i].ToString(CultureStrings.FormatByteToHex); text += " "; i += 1; } return(text); }
public static Bitmap DownloadImage(string imageUrl) { using HttpClient httpClient = new HttpClient(); using Image bmap = Image.FromStream(httpClient.GetStreamAsync(imageUrl).Result); if (bmap.PropertyIdList.Contains(0x112)) { System.Drawing.Imaging.PropertyItem propItem = bmap.GetPropertyItem(0x112); bmap.RotateFlip(GetRotation(propItem.Value[0])); } double scaleFactor = (double)Console.WindowWidth * 0.9 / bmap.Width; return(new Bitmap(bmap, (int)(bmap.Width * scaleFactor), (int)(bmap.Height * scaleFactor))); }
public static void SetProperty(ref System.Drawing.Imaging.PropertyItem prop, int iId, string sTxt) { int iLen = sTxt.Length + 1; byte[] bTxt = new Byte[iLen]; for (int i = 0; i < iLen - 1; i++) { bTxt[i] = (byte)sTxt[i]; } bTxt[iLen - 1] = 0x00; prop.Id = iId; prop.Type = 2; prop.Value = bTxt; prop.Len = iLen; }
private static string DecodeRational64u(System.Drawing.Imaging.PropertyItem propertyItem) { uint dN = BitConverter.ToUInt32(propertyItem.Value, 0); uint dD = BitConverter.ToUInt32(propertyItem.Value, 4); uint mN = BitConverter.ToUInt32(propertyItem.Value, 8); uint mD = BitConverter.ToUInt32(propertyItem.Value, 12); uint sN = BitConverter.ToUInt32(propertyItem.Value, 16); uint sD = BitConverter.ToUInt32(propertyItem.Value, 20); decimal deg; decimal min; decimal sec; // Found some examples where you could get a zero denominator and no one likes to devide by zero if (dD > 0) { deg = (decimal)dN / dD; } else { deg = dN; } if (mD > 0) { min = (decimal)mN / mD; } else { min = mN; } if (sD > 0) { sec = (decimal)sN / sD; } else { sec = sN; } if (sec == 0) { return(string.Format("{0}° {1:0.###}'", deg, min)); } else { return(string.Format("{0}° {1:0}' {2:0.#}\"", deg, min, sec)); } }
/// <summary> /// Gets a .NET PropertyItem for this metadata tag. /// </summary> /// <returns>The .NET PropertyItem.</returns> public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem() { System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem(); item.Id = ID; item.Len = (int)Length; item.Type = (short)Type; byte[] data = new byte[item.Len]; byte * ptr = (byte *)FreeImage.GetTagValue(tag); for (int i = 0; i < data.Length; i++) { data[i] = ptr[i]; } item.Value = data; return(item); }
/// <summary> /// Modifies an Profile image. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="w">The w.</param> /// <param name="h">The h.</param> /// <param name="PersonID">Profile Image to work on</param> /// <returns>New Image Id</returns> private bool ModifyImage(int x, int y, int w, int h, Person person) { string ProfilDirSetting = ConfigurationManager.AppSettings["ProfileImage"]; if (string.IsNullOrWhiteSpace(ProfilDirSetting)) { throw new ArgumentNullException(); } var ProfilBilled = string.Format(ProfilDirSetting, person.PersonID); if (System.IO.File.Exists(Server.MapPath(ProfilBilled))) { Image img = Image.FromFile(Server.MapPath(ProfilBilled)); using (System.Drawing.Bitmap _bitmap = new System.Drawing.Bitmap(428, 550)) { _bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution); using (Graphics _graphic = Graphics.FromImage(_bitmap)) { _graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; _graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; _graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; _graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; _graphic.Clear(Color.White); //_graphic.DrawImage(img, 0, 0, w, h); _graphic.DrawImage(img, new Rectangle(0, 0, 428, 550), x, y, w, h, GraphicsUnit.Pixel); //_graphic.DrawImage(img, new Rectangle(0, 0, w, h), x, y, w, h, GraphicsUnit.Pixel); //_graphic.DrawImage(img, 0, 0, img.Width, img.Height); //_graphic.DrawImage(img, new Rectangle(0, 0, 428, 550), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel); } System.Drawing.Imaging.PropertyItem prop = img.PropertyItems[0]; SetProperty(ref prop, 270, string.Format("Username: {0}, {1}", person.UserName, person.FullName)); _bitmap.SetPropertyItem(prop); SetProperty(ref prop, 33432, "Copyright Natteravnene www.natteravnene.dk"); _bitmap.SetPropertyItem(prop); //TODO: Set more properties img.Dispose(); _bitmap.Save(Server.MapPath(ProfilBilled), System.Drawing.Imaging.ImageFormat.Jpeg); } } return(true); }
private static string Decode(System.Drawing.Imaging.PropertyItem propertyItem) { uint dN = BitConverter.ToUInt32(propertyItem.Value, 0); uint dD = BitConverter.ToUInt32(propertyItem.Value, 4); uint mN = BitConverter.ToUInt32(propertyItem.Value, 8); uint mD = BitConverter.ToUInt32(propertyItem.Value, 12); uint sN = BitConverter.ToUInt32(propertyItem.Value, 16); uint sD = BitConverter.ToUInt32(propertyItem.Value, 20); decimal deg; decimal min; decimal sec; if (dD > 0) { deg = (decimal)dN / dD; } else { deg = dN; } if (mD > 0) { min = (decimal)mN / mD; } else { min = mN; } if (sD > 0) { sec = (decimal)sN / sD; } else { sec = sN; } if (sec == 0) { return(string.Format($"{deg}°{min:0.###}'")); } else { return(string.Format($"{deg}°{min:0}'{sec:0.#}\"")); } }
public System.Drawing.Imaging.PropertyItem TryCreateGdipPropertyItem() { // Skip the Interoperability IFD because GDI+ does not support it. // https://docs.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-constant-image-property-tag-constants if (!TagDataTypeUtil.IsKnownToGDIPlus(Type) || Section == MetadataSection.Interop) { return(null); } System.Drawing.Imaging.PropertyItem propertyItem = PaintDotNet.SystemLayer.PdnGraphics.CreatePropertyItem(); propertyItem.Id = TagId; propertyItem.Type = (short)Type; propertyItem.Len = data.Length; propertyItem.Value = (byte[])data.Clone(); return(propertyItem); }
/************************************************************************ * The Input: a path to an image. * The Output: The datetime. * The Function operation: The function finds the image's datetime. *************************************************************************/ public static DateTime GetDateTakenFromImage(string path) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) using (Image myImage = Image.FromStream(fs, false, false)) { try { System.Drawing.Imaging.PropertyItem propItem = myImage.GetPropertyItem(36867); string dateTaken = r.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2); return(DateTime.Parse(dateTaken)); } catch { //Incase the image doesn't have a date return the files date. return(File.GetCreationTime(path)); } } }
private static object ValueOf(System.Drawing.Imaging.PropertyItem item) { if (item == null) { return(null); } // ========================================================================= // DateTimeOriginal(撮影日時) // ========================================================================= if (item.Id == 0x9003) { string value = Encoding.ASCII.GetString(item.Value, 0, 19); try { return(DateTime.ParseExact(value, "yyyy:MM:dd HH:mm:ss", null)); } catch { } try { return(DateTime.ParseExact(value, "yyyy:MM:dd H:mm:ss", null)); } catch { } Console.WriteLine("[ERROR] 0x9003:DateTimeOriginal 解析できませんでした。この書式には対応していません。[" + value + "]"); return(null); } //if (item.id == 0x9004) //{ // ; //} return(item.Value); }
public static bool setMetadata(string file, string artistsMetadata = "", string tagsMetadata = "") { if (System.IO.File.Exists(file)) { Image openImage = Image.FromFile(file); System.Drawing.Imaging.PropertyItem imageProperty = openImage.PropertyItems[0]; imageProperty = openImage.PropertyItems[0]; SetProperty(ref imageProperty, 315, artistsMetadata); openImage.SetPropertyItem(imageProperty); imageProperty = openImage.PropertyItems[0]; SetProperty(ref imageProperty, 270, tagsMetadata); openImage.SetPropertyItem(imageProperty); openImage.Save(file); return(true); } return(false); }
private string getPropertyValue(System.Drawing.Imaging.PropertyItem property) { if (property.Type == 2) { return(getAsciiProperty(ref property)); } else if (property.Type == 3) { return(getUInt16Property(ref property)); } else if (property.Type == 4) { return(getUInt32Property(ref property)); } else if (property.Type == 5) { return(getUInt32UInt32Property(ref property)); } else { return(getHexProperty(ref property)); } }
/// <summary> /// retrieves the datetime from the image at the received path /// </summary> /// <param name="path">the path to the image to have its takendate extracted</param> /// <returns>the datetime objects describing its datetaken property</returns> private static DateTime GetDateTakenFromImage(string path) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) using (System.Drawing.Image myImage = System.Drawing.Image.FromStream(fs, false, false)) { System.Drawing.Imaging.PropertyItem propItem = null; if (myImage.PropertyIdList.Any(x => x == 36867) || myImage.PropertyIdList.Any(x => x == 306)) { if (myImage.PropertyIdList.Any(x => x == 36867)) { propItem = myImage.GetPropertyItem(36867); } else { propItem = myImage.GetPropertyItem(306); } string dateTaken = r.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2); return(DateTime.Parse(dateTaken)); } //if no property of date taken on the file (picture) take the date of creation return(new FileInfo(path).CreationTime); } }
internal void LoadImageDataFromByte(Triggernometry.RealPlugin plug, Graphics g, byte[] data) { GifData gif = GetGifData(data); using (MemoryStream ms = new MemoryStream(data)) { using (System.Drawing.Image i = System.Drawing.Image.FromStream(ms)) { System.Drawing.Bitmap b = (System.Drawing.Bitmap)i; System.Drawing.Imaging.FrameDimension CurrentFd = new System.Drawing.Imaging.FrameDimension(i.FrameDimensionsList[0]); NumberOfFrames = i.GetFrameCount(CurrentFd); IsAnimated = (NumberOfFrames > 1); if (IsAnimated == true) { Frames = new List <Image>(); FrameDelays = new List <int>(); System.Drawing.Imaging.PropertyItem delay = i.GetPropertyItem(0x5100); Color tc; bool hastc = false; if (gif.TransparencyIndex >= 0) { tc = gif.Palette[gif.TransparencyIndex]; hastc = true; } else { tc = gif.Palette[0]; } for (int h = 0; h < NumberOfFrames; h++) { int delayn = (delay.Value[h * 4] + (delay.Value[(h * 4) + 1] * 256)) * 10; FrameDelays.Add(delayn); i.SelectActiveFrame(CurrentFd, h); System.Drawing.Image ifa = ((System.Drawing.Image)i.Clone()); byte[] idata = ImageToByte(ifa); if (hastc == true) { if (gif.TransparencyIndex != gif.BackgroundColor) { // hack in case transparency color is different from bgcolor (some gifs have this shit) SetTransparencyIndex(idata, (byte)gif.BackgroundColor); } else { for (int j = 0; j < gif.TransparencyIndex; j++) { if ((gif.Palette[j].R == tc.R) && (gif.Palette[j].R == tc.G) && (gif.Palette[j].R == tc.B)) { // net itself might have selected an earlier color as new transparency color // hack to reset transparency index to match if so SetTransparencyIndex(idata, (byte)j); break; } } } } Frames.Add(g.CreateImage(idata)); } CurrentFrame = -1; AdvanceFrame(); } else { OriginalImage = g.CreateImage(data); } } } }
private string getUInt32UInt32Property(ref System.Drawing.Imaging.PropertyItem property) { return(System.BitConverter.ToUInt32(property.Value, 0).ToString() + CultureStrings.MarkerSlash + System.BitConverter.ToUInt32(property.Value, 4).ToString()); }
private string getAsciiProperty(ref System.Drawing.Imaging.PropertyItem property) { return(new System.Text.ASCIIEncoding().GetString(property.Value, 0, property.Len - 1)); }
/// <param name="filename">Animated Image (ie: animated gif).</param> public static AnimatedImageData GetAnimatedImageData(string fileName) { lock (AnimatedImageDatas) { int index = AnimatedImageDataFileNames.IndexOf(fileName); if (index >= 0) { // AnimatedImageData Already Exists // move it to the end of the array and return it AnimatedImageData data = AnimatedImageDatas[index]; string name = AnimatedImageDataFileNames[index]; AnimatedImageDatas.RemoveAt(index); AnimatedImageDataFileNames.RemoveAt(index); AnimatedImageDatas.Add(data); AnimatedImageDataFileNames.Add(name); return(AnimatedImageDatas[AnimatedImageDatas.Count - 1]); } else { // New AnimatedImageData System.Drawing.Image image = System.Drawing.Image.FromFile(fileName); AnimatedImageData data = new AnimatedImageData(); //// Get Frame Duration int frameDuration = 0; try { System.Drawing.Imaging.PropertyItem frameDelay = image.GetPropertyItem(0x5100); frameDuration = (frameDelay.Value[0] + frameDelay.Value[1] * 256) * 10; } catch { } if (frameDuration > 10) { data.FrameDuration = frameDuration; } else { data.FrameDuration = AnimatedImage.DEFAULT_FRAME_DURATION; } //// Store AnimatedImageData AnimatedImageDatas.Add(data); AnimatedImageDataFileNames.Add(fileName); // Limit amount of Animations in Memory if (AnimatedImageDatas.Count > MAX_ANIMATIONS) { AnimatedImageDatas[0].CancelLoading = true; for (int i = 0; i < AnimatedImageDatas[0].Frames.Count; i++) { AnimatedImageDatas[0]?.Frames[i]?.Dispose(); } AnimatedImageDatas.RemoveAt(0); AnimatedImageDataFileNames.RemoveAt(0); } //// Get Frames LoadingAnimatedImage loadingAnimatedImage = new LoadingAnimatedImage(image, data); Thread loadFramesThread = new Thread(new ThreadStart(loadingAnimatedImage.LoadFrames)); loadFramesThread.Name = "AnimationLoadThread - " + fileName; loadFramesThread.IsBackground = true; loadFramesThread.Start(); while (data.Frames.Count <= 0) { ; // wait for at least one frame to be loaded } return(data); } } }
private void TestFunc1(string fileName) { Bitmap bmp = new Bitmap(fileName); foreach (System.Drawing.Imaging.PropertyItem p in bmp.PropertyItems) { // 0x9003 - 原画像データの生成日時 // 0x9004 - デジタルデータの作成日時 // 0x0001-北緯(N) or 南緯(S)(Ascii) // 0x0002-緯度(数値)(Rational) // 0x0003-東経(E) or 西経(W)(Ascii) // 0x0004-経度(数値)(Rational) // 0x0005-高度の基準(Byte) // 0x0006-高度(数値)(Rational) // 0x0007-GPS時間(原子時計の時間)(Rational) // 0x0008-測位に使った衛星信号(Ascii) // 0x0009-GPS受信機の状態(Ascii) // 0x000A-GPSの測位方法(Ascii) // 0x000B-測位の信頼性(Rational) // 0x000C-速度の単位(Ascii) // 0x000D-速度(数値)(Rational) if (p.Type == 2 && p.Len > 0) { string s = System.Text.Encoding.ASCII.GetString(p.Value); s = s.Trim(new char[] { '\0' }); System.Diagnostics.Debug.Print("{0} - [{1}][{2}]", p.Id, s, p.Type); } else { System.Diagnostics.Debug.Print("{0} - [{1}][{2}]", p.Id, p.Value, p.Type); } } System.Drawing.Imaging.PropertyItem p1 = bmp.PropertyItems[0]; { // 緯度 p1.Id = 1; p1.Type = 2; p1.Value = ConvertTo("N"); p1.Len = p1.Value.Length; bmp.SetPropertyItem(p1); p1.Id = 2; p1.Type = 5; p1.Value = ConvertTo(new UInt32[] { 38, 1, 2, 1, 37, 10 }); p1.Len = p1.Value.Length; bmp.SetPropertyItem(p1); // 経度 p1.Id = 3; p1.Type = 2; p1.Value = ConvertTo("E"); p1.Len = p1.Value.Length; bmp.SetPropertyItem(p1); p1.Id = 4; p1.Type = 5; p1.Value = ConvertTo(new UInt32[] { 140, 1, 44, 1, 175, 10 }); p1.Len = p1.Value.Length; bmp.SetPropertyItem(p1); // 高度 p1.Id = 5; p1.Type = 7; p1.Value = new byte[] { 0x00 }; p1.Len = p1.Value.Length; bmp.SetPropertyItem(p1); p1.Id = 6; p1.Type = 5; p1.Value = ConvertTo(new UInt32[] { 40, 1 }); p1.Len = p1.Value.Length; bmp.SetPropertyItem(p1); } String newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fileName), "HOGE.jpg"); bmp.Save(newPath); }
public void SetPropertyItem(System.Drawing.Imaging.PropertyItem propitem) { }