Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Forum översikt / inlägg

Posta nytt inlägg


Läsa EXIF metadata

Postades av 2005-01-31 00:52:20 - Anders Larsson, i forum asp.net generellt, Tråden har 3 Kommentarer och lästs av 1113 personer

Jag försöker läsa ut EXIF metadata ut en JPG-bild med följande kod:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;

using System.Data;

namespace iUpload
{
	public class ExifMetadata
	{
		public ExifMetadata()
		{
		}

		public struct MetadataDetail
		{
			public string Hex;
			public string RawValueAsString;
			public string DisplayValue;
		}

		public struct Metadata
		{
			public MetadataDetail EquipmentMake;
			public MetadataDetail CameraModel;
			public MetadataDetail ExposureTime;
			public MetadataDetail Fstop;
			public MetadataDetail DatePictureTaken;
			public MetadataDetail ShutterSpeed;
			public MetadataDetail ExposureCompensation;
			public MetadataDetail MeteringMode;
			public MetadataDetail Flash;
			public MetadataDetail XResolution;
			public MetadataDetail YResolution;
			public MetadataDetail ImageWidth;
			public MetadataDetail ImageHeight;
		}

		public string LookupExifValue(string Description, string Value)
		{
			string DescriptionValue = null;

			if (Description == "MeteringMode")
			{
				switch(Value)
				{
					case "0":
						DescriptionValue = "Unknown";
						break;
					case "1":
						DescriptionValue = "Average";
						break;
					case "2":
						DescriptionValue = "Center Weighted Average";
						break;
					case "3":
						DescriptionValue = "Spot";
						break;
					case "4":
						DescriptionValue = "Multi-spot";
						break;
					case "5":
						DescriptionValue = "Multi-segment";
						break;
					case "6":
						DescriptionValue = "Partial";
						break;
					case "255":
						DescriptionValue = "Other";
						break;
				}
			}

			if (Description == "ResolutionUnit")
			{
				switch(Value)
				{
					case "1":
						DescriptionValue = "No Units";
						break;
					case "2":
						DescriptionValue = "Inch";
						break;
					case "3":
						DescriptionValue = "Centimeter";
						break;
				}
			}

			if (Description == "Flash")
			{
				switch(Value)
				{
					case "0":
						DescriptionValue = "Flash did not fire";
						break;
					case "1":
						DescriptionValue = "Flash fired";
						break;
					case "5":
						DescriptionValue = "Flash fired but strobe return 	light not detected";
						break;
					case "7":
						DescriptionValue = "Flash fired and strobe return light detected";
						break;
				}
			}
			return DescriptionValue;
		}

		public Metadata GetExifMetadata(string PhotoName)
		{
			// Create an instance of the 	image to gather metadata from
										 
			Image MyImage = Image.FromFile(PhotoName);

			// Create an integer array to hold the property id list,
			// and populate it with the list	from my image.
													 
			/* Note: this only generates a list of integers, one for for each PropertyID.
			 * We will populate the PropertyItem values later. */

			int[] MyPropertyIdList = MyImage.PropertyIdList;

			// Create an array of 	PropertyItems, but don't populate it yet.

			PropertyItem[] MyPropertyItemList = new PropertyItem[MyPropertyIdList.Length];

			// Create an instance of Metadata 		and populate Hex codes (values populated later)

			Metadata MyMetadata = new Metadata();

			MyMetadata.EquipmentMake.Hex = "10f";
			MyMetadata.CameraModel.Hex = "110";
			MyMetadata.DatePictureTaken.Hex = "9003";
			MyMetadata.ExposureTime.Hex = "829a";
			MyMetadata.Fstop.Hex = "829d"; 
			MyMetadata.ShutterSpeed.Hex = "9201";
			MyMetadata.ExposureCompensation.Hex = "9204";
			MyMetadata.MeteringMode.Hex = "9207";
			MyMetadata.Flash.Hex = "9209";

			// Declare an ASCIIEncoding to 	use for returning string values from bytes 

			System.Text.ASCIIEncoding Value =  new System.Text.ASCIIEncoding();
            
			// Populate MyPropertyItemList.
			// For each propertyID...
			int index = 0;
			foreach (int MyPropertyId in MyPropertyIdList)
			{
				// ... try to call 	GetPropertyItem (it crashes if PropertyItem has length 0 so use Try/Catch)

				try
				{
					// Assign the 	image's PropertyItem to the PropertyItem array MyPropertyItemList [index] = MyImage.GetPropertyItem(MyPropertyId);
					// Assign each 	element of MyMetadata

					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") == "10f") // EquipmentMake
					{
                        MyMetadata.EquipmentMake.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
						MyMetadata.EquipmentMake.DisplayValue =	Value.GetString(MyPropertyItemList[index].Value);
					}

					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") == "110") // CameraModel
					{
						MyMetadata.CameraModel.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
						MyMetadata.CameraModel.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
					}



					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") == "9003") // DatePictureTaken
					{
						MyMetadata.DatePictureTaken.RawValueAsString =BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
						//MyMetadata.DatePictureTaken.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
						MyMetadata.DatePictureTaken.DisplayValue = index.ToString();
					}

			
					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") 	== "9207") // MeteringMode
					{
						MyMetadata.MeteringMode.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
						MyMetadata.MeteringMode.DisplayValue = LookupExifValue("MeteringMode",BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value,0).ToString());
					}

					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") == "9209") // Flash
					{
						MyMetadata.Flash.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
						MyMetadata.Flash.DisplayValue = LookupExifValue("Flash",BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value,0).ToString());
					}

					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") == "829a") // ExposureTime
					{
	                    MyMetadata.ExposureTime.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);

						string StringValue = "";
						for (int Offset = 0; Offset < MyImage.GetPropertyItem (MyPropertyId).Len; 
							Offset = Offset + 4){StringValue += BitConverter.ToInt32(MyImage.GetPropertyItem(MyPropertyId).Value,Offset).ToString() + "/";
						}

				
						MyMetadata.ExposureTime.DisplayValue =StringValue.Substring(0,StringValue.Length-1);
					}

			
					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x")	== "829d") // F-stop
					{
						MyMetadata.Fstop.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);

						int int1;
						int int2;
						int1 =	BitConverter.ToInt32(MyImage.GetPropertyItem(MyPropertyId).Value,0);
						int2 =	BitConverter.ToInt32(MyImage.GetPropertyItem(MyPropertyId).Value,4);

						MyMetadata.Fstop.DisplayValue = "F/" +(int1/int2);
					}

					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") == "9201") // ShutterSpeed
					{
						
						MyMetadata.ShutterSpeed.RawValueAsString =	BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);

						string StringValue = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value).Substring(0,2);
						MyMetadata.ShutterSpeed.DisplayValue = "1/" + StringValue;
					}


					if (MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x") == "9204") // ExposureCompensation
					{
                        MyMetadata.ExposureCompensation.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);

						string	StringValue = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value).Substring(0,1);

						MyMetadata.ExposureCompensation.DisplayValue = StringValue + " (Needs work to confirm accuracy)";
					}

				}
				catch (Exception exc)
				{
				// if it is the expected error, do nothing
				if (exc.GetType().ToString() != "System.ArgumentNullException")
				{}
				}
                finally

				{
					index++;
					}
				}


			MyMetadata.XResolution.DisplayValue = MyImage.HorizontalResolution.ToString();
			MyMetadata.YResolution.DisplayValue = MyImage.VerticalResolution.ToString();
			MyMetadata.ImageHeight.DisplayValue = MyImage.Height.ToString();
			MyMetadata.ImageWidth.DisplayValue = MyImage.Width.ToString();
			return MyMetadata;
		}
	}
}






samt på sidan


string MyPicture = ConfigurationSettings.AppSettings["imgBase"]+enhet+"\\"+hashValue+"."+Imaging.getImageExt(MyFile.FileName);
            
            // create an instance of the class Utilities.ExifMetadata
			ExifMetadata MyExifMetadata = new iUpload.ExifMetadata();

			//Utilities.ExifMetadata 	MyExifMetadata = new Utilities.ExifMetadata();

            // create an instance of the Metadata struct
            ExifMetadata.Metadata MyMetadata;

            // Populate the instance of the struct by calling GetExifMetadata
            MyMetadata = MyExifMetadata.GetExifMetadata(MyPicture);

            //textBox1.Clear();
            Response.Write("<p>.</p>Equipment Make: " + MyMetadata.EquipmentMake.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Camera Model: " + MyMetadata.CameraModel.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Date Picture Taken: " + MyMetadata.DatePictureTaken.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Exposure Compensation: " + MyMetadata.ExposureCompensation.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Exposure Time: " + MyMetadata.ExposureTime.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Flash: " + MyMetadata.Flash.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Fstop: " + MyMetadata.Fstop.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Metering Mode: " + MyMetadata.MeteringMode.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Shutter Speed: " + MyMetadata.ShutterSpeed.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("X Resolution: " + MyMetadata.XResolution.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Y Resolution: " + MyMetadata.YResolution.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Image Width: " + MyMetadata.ImageWidth.DisplayValue);
            Response.Write("<p>.</p>");
            Response.Write("Image Height: " + MyMetadata.ImageHeight.DisplayValue);
 


Men jag får det inte att fungera... de flesta värdena returnerar ingenting. Har sökt som en galning på Google, men inte hittat något vettigt. Någon som har någon idé?


Svara

Sv: Läsa EXIF metadata

Postades av 2005-02-10 22:08:19 - Anders Larsson

Ingen som har något tips?


Svara

Sv:Läsa EXIF metadata

Postades av 2005-02-11 10:20:26 - Johan Svensson

Testa med en kortare fråga och en kortare kodlistning så kanske folk orkar läsa...och för säkerhetsskull gör detta i en ny tråd.

// Johan


Svara

Sv: Läsa EXIF metadata

Postades av 2006-12-14 23:43:42 - Per Bäckman

Jag hittade detta:
http://www.spaz.com/mr/work/aspexiffuncs/
(har inte testat själv men exemplet som är med gör att det ser lovande ut)
/Per


Svara

Nyligen

  • 09:09 Vill du köpa medicinska tester?
  • 12:47 Vem beviljar assistansen – kommune
  • 14:17 Någon med erfarenhet av hemstädnin
  • 14:14 Bör man använda sig av en båtförme
  • 14:12 Finns det någon intressant hundblo
  • 14:25 Tips på verktyg för att skapa QR-k
  • 14:23 Tips på verktyg för att skapa QR-k
  • 20:52 Fungerer innskuddsbonuser egentlig

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 569 170
27 953
271 705
4 068
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies