 |
|
 |
Firstly thanks, oh thanks, oh thanks for a superb class. This has saved my a lot of time.
I came across a couple of optimizations that I thought you might be interested in.
Firstly I took out the _image reference and added a
private PropertyItem[] _metadata;
so the whole image was not in memory for the scope of info instance.
In addition, I found this article
http://www.pixvillage.com/blogs/devblog/archive/2005/03/17/159.aspx
which provides a quicker method of loading the image data. So I added this function, which your constructor calls
private void FastLoadImage(string imageFileName)
{
using (FileStream stream = new FileStream(imageFileName, FileMode.Open, FileAccess.Read))
using (Image image = Image.FromStream(stream,true,false))
_metadata = image.PropertyItems;
}
I then created a couple of wrapper methods for getting the info from the _metaData variable
private PropertyItem GetMetaData(PropertyTagId tag)
{
PropertyItem item;
for (int i = 0; i < _metadata.Length; i++)
{
item = _metadata[i];
if (item.Id == (int)tag)
return item;
}
return null;
}
private Object GetMetaDataValue(PropertyTagId tag)
{
return PropertyTag.getValue(GetMetaData(tag));
}
which simplifies property call
e.g.
return (Fraction) GetMetaDataValue(PropertyTagId.XResolution);
I managed to extract the metadata from 6288 files in 42 seconds after these changes.
Though you might be interested.
-- modified at 13:59 Wednesday 25th October, 2006
|
|
|
|
 |
|
 |
Hi,
I've downloaded the EXIFextractor.dll but I don't know how to refer to it. Would you please show me how? (I'm asp.Net programmer)
Thanks
|
|
|
|
 |
|
 |
Hi,
first of all add a reference to your ASP.NET project. Then add using gma.Drawing.ImageInfo; at top of your codebehind class. Now you are ready to use it in your page. Add this snippet for example in Page_Load method
Image img = Image.FromFile("c:\test.jpg");
Info inf=new Info(pictureBox.Image);
foreach (string propertyname in inf.PropertyItems.Keys)
{
Response.Write(propertyname,
(inf.PropertyItems[propertyname]).ToString());
}
|
|
|
|
 |
|
 |
Thank you very much for your help.
Now on top of code behind page when I add Imports I can see the gma.Drawing.ImageInfo there. But your example to test the dll I think is not asp.net. Can convert those lines to asp.net syntax (I'm just a beginer)?
Thanks,
Regards
MD
|
|
|
|
 |
|
 |
Thank you,
I've found a gma.Drawing.ImageInfo help. It works now.
Thanks.
MD
|
|
|
|
 |
|
 |
I have used your program to get metadata of images.
When you open the image in Photoshop you will see an owner url field.
I couldn’t find that value from the application.
How do you access that field?
Janaka
|
|
|
|
 |
|
 |
Beings i don't know C that well, is there a way to port this to visual basic? I am trying to massive update all of the datecreated tags with the OriginalDate tag with about 7000 pictures.
Mac
|
|
|
|
 |
|
 |
I can advice you to leave the code on c# compile it as an assembly and refer to it from vb.net.
|
|
|
|
 |
|
 |
Hi,
if You successfully import code in Visual Basic can you send me how it look in VB.
Alen.
|
|
|
|
 |
|
 |
Woud you like to rewrite it in VisualBasic or you want to use it in VisualBasic?
|
|
|
|
 |
|
 |
I wan to use it in VB.
Alen.
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
The only way I have found to add image meta data within the .net framework is to first use the .GetPropertyItem(...) command and then alter the id and value so that it points to a new location. Then use the .SetPropertyItem(...) and do an image save command. So for example if you wanted to add an image description:
PropertyItem propI = m_Bitmap.GetPropertyItem(269); //Get a PropertyItem from image in
//this case the document name
propI.Id = 270; //change id so that it is now the id for the image description
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); //to convert ascii to
//a byte array
string temp = "Text You Want To Add To The Image Description";
byte[] texttoadd = encoding.GetBytes(temp); //store in byte array
propI.Value = texttoadd; //change value of the PropertyItem.
m_Bitmap.SetPropertyItem(propI); // Set the PropertyItem
m_Bitmap.Save("C:\image.jpg");
This only works if the property item you change exists in the image in the first place. Most of this info, as well as all the common metadata id numbers can be found on the MSDN website. Hope this helps.
-Matt
|
|
|
|
 |
|
 |
how to modify and save date time value?
and another is
I open a jpg from file and update property.
It can't update to the file that I open.
I don't want to save image with another name.
|
|
|
|
 |
|
 |
how to get the MakerNote,ExposureTime,ExposureBias,Flash,UserComment and so on.
thank you.
|
|
|
|
 |
|
 |
inf=new Info(pictureBox.Image);
MessageBox.Show(inf.PropertyItems[PropertyTagId.ExifFlash.ToString()].ToString());
MessageBox.Show(inf.PropertyItems[PropertyTagId.ExifExposureBias.ToString()].ToString());
See the example, pobably you can find an answer even there! :->
|
|
|
|
 |
|
 |
Does anyone know how to properly embed the ICM tag in the JPG's EXIF info? I don't have .Net and find only .Net solutions to decoding the Tag. The tag PropertyTagICCProfile, I presume is the one to fill but I cant figure out in c++ how to decode this byte array on my visual studio 6. I noticed custom tags try to fill this value but Adobe1998.icc wont. It seems to be the only logical tag to embed the color profile name. Any suggestions are appreciated.
Thanks
zBz
ZeroByZero
|
|
|
|
 |
|
 |
I am writing an image app and I need an easy way to view and set the exif data in an image. I will be display and sorting my images based on what is in the exif data. I specifically need to get to the user definable entries of the exif data. The code in this article goes part way, but I don't see how to access other attributes.
Thanks,
Bret
|
|
|
|
 |
|
 |
Hi !
Thanks for the these nice classes, they made my day!
There is one thing I was missing: a dispose method. I was running into trouble, because an imgagefile stays locked until it is completely removed by the gc. This may take a while. I added the Disposable interface to the Info class, so that I can call the release of the ressource as I whish. This solved my locking problem.
Bye
Michael
public class Info : IDisposable
{
......
cutted
......
#region IDisposable Member
public void Dispose()
{
_image.Dispose();
}
#endregion
}
|
|
|
|
 |
|
 |
Hi Michael,
I have the same problem.
I allways get the message "not enough memory".
Please tell me the exactly way, where I must
write the iDisable class.
thanks
greetings from germany
michael too
mimuel
|
|
|
|
 |
|
 |
Very nice code, simple, would suggest adding ImageDescription
///
/// Image description
///
public string ImageDescription
{
get
{
return (string) PropertyTag.getValue(_image.GetPropertyItem((int)PropertyTagId.ImageDescription));
}
}
Then it's easy to a make a web photogallery system
BTW
Freeware utility to write and read the EXIF
http://www.exifer.friedemann.info/
|
|
|
|
 |
|
 |
Does this work.
I seem to get : index was outside the bounds of the array...
|
|
|
|
 |
|
 |
Hi, this article realy heped a lot!!
I also looking for a sort of file header check (I think). I want to check the file type so that I can be sure that a file with the extension jpg is indeed a jpg image inside. Because we work file 100Mb+ file's it's not wanted to open the entire file to perform this check, currently I open the file in .net and get the imagetype to check the content, this is way to resource expensive for the future. I don't have any clue how to start reading this header, what to look for and even if this is a good solution. Anyone who can help me ?
|
|
|
|
 |
|
 |
The simplest way is to open a file stream and read first four bytes. They must by FF D8 FF E0. There are some special cases (less than 1%) which does not pass under this schema. Fore more information see an article below.
Subject: [15] How do I recognize which file format I have,
and what do I do about it?
If you have an alleged JPEG file that your software won't read, it's likely
to be some proprietary JPEG-based format. You can tell what you have by
inspecting the first few bytes of the file:
1. A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0,
followed by two variable bytes (often hex 00 10), followed by 'JFIF'.
2. If you see FF D8 FF at the start, but not the 'JFIF' marker, you
probably have a not-quite-JFIF JPEG file. Most JFIF software should
read it without complaint. If you are using something that is picky
enough to complain about the lack of a JFIF marker, try another decoder.
(Both very old JPEG files and very new ones may lack JFIF markers ---
the new SPIFF standard mentioned above doesn't use a JFIF marker.
So gripe to your software vendor if you find this to be the problem.)
3. A Macintosh PICT file, if JPEG-compressed, will have several hundred
bytes of header (often 726 bytes, but not always) followed by JPEG data.
Look for the 3-byte sequence (hex) FF D8 FF. The text 'Photo - JPEG'
will usually appear shortly before this header, and 'AppleMark' or
'JFIF' will usually appear shortly after it. Strip off everything
before the FF D8 FF and you will usually be able to decode the file.
(This will fail if the PICT image is divided into multiple "bands";
fortunately banded PICTs aren't very common. A banded PICT contains
multiple JPEG datastreams whose heights add up to the total image
height. These need to be stitched back together into one image.
Bailey Brown has some simple tools for this purpose on a Web page at
http://www.isomedia.com/homes/bailey/photo-jpeg/photo-jpeg.html.)
4. If the file came from a Macintosh, it could also be a standard JFIF
file with a MacBinary header attached. In this case, the JFIF header
will appear 128 bytes into the file. Get rid of the first 128 bytes
and you're set.
5. Anything else: it's a proprietary format, or not JPEG at all. If you
are lucky, the file may consist of a header and a raw JPEG data stream.
If you can identify the start of the JPEG data stream (look for FF D8),
try stripping off everything before that.
At least one release of HiJaak Pro writes JFIF files that claim to be
revision 2.01. There is no such spec; the latest JFIF revision is 1.02.
It looks like HiJaak got the high and low bytes backwards. Unfortunately,
most JFIF readers will give up on encountering these files, because the JFIF
spec defines a major version number change to mean an incompatible format
change. If there ever *were* a version 2.01, it would be so numbered
because current software could not read it and should not try. (One wonders
if HiJaak has ever heard of cross-testing with other people's software.)
If you run into one of these misnumbered files, you can fix it with a
binary-file editor, by changing the twelfth byte of the file from 2 to 1.
Nicholas Sherlock
|
|
|
|
 |