<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Drawing</title><link>http://www.pixvillage.com/blogs/devblog/category/12.aspx</link><description>Articles relating to drawing, especially use of the System.Drawing namespace.</description><managingEditor>Buz &amp; Skup</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Buz &amp; Skup</dc:creator><title>Exif Properties in .Net - Part 3 : converting properties</title><link>http://www.pixvillage.com/blogs/devblog/archive/2005/04/19/215.aspx</link><pubDate>Tue, 19 Apr 2005 12:20:00 GMT</pubDate><guid>http://www.pixvillage.com/blogs/devblog/archive/2005/04/19/215.aspx</guid><wfw:comment>http://www.pixvillage.com/blogs/devblog/comments/215.aspx</wfw:comment><comments>http://www.pixvillage.com/blogs/devblog/archive/2005/04/19/215.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.pixvillage.com/blogs/devblog/comments/commentRss/215.aspx</wfw:commentRss><trackback:ping>http://www.pixvillage.com/blogs/devblog/services/trackbacks/215.aspx</trackback:ping><description>  &lt;p&gt;
   In the first post of this Exif series, I talked about a technique for &lt;A href="http://www.pixvillage.com/blogs/devblog/archive/2005/03/17/159.aspx"&gt;
    loading Exif properties&lt;/a&gt; as fast as GDI+ is able to do.&lt;br /&gt;
   The second post was dealing with &lt;A href="http://www.pixvillage.com/blogs/devblog/archive/2005/03/27/176.aspx"&gt;
    adding new properties&lt;/a&gt; to an empty image.&lt;/p&gt;
  &lt;p&gt;Now it's time to look more precisely at the Exif properties. How is a 
   PropertyItem structured ?&lt;br /&gt;
   The final goal of this post is to convert the raw data exposed by GDI+ (and the 
   .Net Framework) into more useable data types.
  &lt;/p&gt;
  &lt;p&gt;
   An Exif property consists in the following information:&lt;/p&gt;
  &lt;ul&gt;
   &lt;li&gt;
    An &lt;b&gt;identifier&lt;/b&gt;, determining the "meaning" of the property.&lt;/li&gt;
   &lt;li&gt;
    A &lt;b&gt;data type&lt;/b&gt;, indicating how the data are represented.&lt;/li&gt;
   &lt;li&gt;
    A &lt;b&gt;length&lt;/b&gt; (the number of bytes the property data contains).&lt;/li&gt;
   &lt;li&gt;
    A &lt;b&gt;value&lt;/b&gt; which is a raw array of bytes.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;
   The Exif property data type is a 16-bit integer, but it's quite simple to build 
   an &lt;i&gt;enum&lt;/i&gt; type that maps the values to a more comprehensive type :
  &lt;/p&gt;
  &lt;!-- ExifPropertyType code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid" onclick="var i=this.sel,j;for(j=0;j&lt;3;j++)this.childNodes[2+j*2].checked=j==i;if(i==this.selold)return;var sh=new Array('none',''),o=this.parentNode;j=i==0?0:1;this.selold=i;o.childNodes[1].style.display=sh[j];o.childNodes[2].style.display=sh[1-j];o=o.childNodes[1];var h =o.offsetHeight;o.style.height=i==1?'200pt':'';if(i==1 &amp;&amp; o.offsetHeight&gt;h)o.style.height=h;"
    sel="1" selold="1"&gt;&lt;b&gt; Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;&lt;input type="Radio" onclick="parentNode.sel=0" name="2642bbc82b3e4954b83504567c000b2c"
     ID="Radio4" VALUE="Radio4"&gt;Hide&lt;input type="Radio" onclick="parentNode.sel=1" name="2642bbc82b3e4954b83504567c000b2c"
     checked ID="Radio5" VALUE="Radio5"&gt;Scroll&lt;input type="Radio" onclick="parentNode.sel=2" name="2642bbc82b3e4954b83504567c000b2c"
     ID="Radio6" VALUE="Radio6"&gt;Full&lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New';Height:200"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt;
     &amp;lt;summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#008000"&gt; Defines types for Exif Properties.&lt;/font&gt;&lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
    &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; enum&lt;/font&gt; ExifPropertyType 
    {&lt;div style="margin-left:20pt"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is an array of bytes.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     Byte = 1,&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is a null-terminated ASCII string.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;remarks&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;If 
      you set&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see 
      cref=&amp;quot;PropertyItem.Type&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;PropertyItem.Type&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/see&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;
      to&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see cref=&amp;quot;PropertyItem.Type&amp;quot;/&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;, 
      you should set the length data member to the length of the string including the 
      NULL terminator. For example, the string HELLO would have a length of 6.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/remarks&amp;gt;&lt;/font&gt;&lt;br&gt;
     Ascii = 2,&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is an array of signed short (16-bit) integers.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     UInt16 = 3,&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is an array of unsigned long (32-bit) integers.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     UInt32 = 4,&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is an array of pairs of unsigned long integers. Each pair 
      represents a fraction; the first integer is the numerator and the second 
      integer is the denominator.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     URational = 5,&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is an array of bytes that can hold values of any data type.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     Raw = 7,&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is an array of signed long (32-bit) integers.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     Int32 = 9,&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Specifies that the value 
      data member is an array of pairs of signed long integers. Each pair represents 
      a fraction; the first integer is the numerator and the second integer is the 
      denominator.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     Rational = 10,&lt;/div&gt;
    }&lt;/div&gt;
   &lt;div style="display:none;background-color:#ffffff"&gt;&lt;b&gt; . . .&lt;/b&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- ExifPropertyType code end --&gt;
  &lt;p&gt;
   As you can see in the code above, most of the data types are simple and can be 
   directly mapped to .Net data types, excepted for rational and unsigned rational 
   values. We need to create a .Net representation for each of them :&lt;/p&gt;
  &lt;ul&gt;
   &lt;li&gt;
    Rational :&lt;/li&gt;
  &lt;/ul&gt;
  &lt;!-- Rational code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid" onclick="var i=this.sel,j;for(j=0;j&lt;3;j++)this.childNodes[2+j*2].checked=j==i;if(i==this.selold)return;var sh=new Array('none',''),o=this.parentNode;j=i==0?0:1;this.selold=i;o.childNodes[1].style.display=sh[j];o.childNodes[2].style.display=sh[1-j];o=o.childNodes[1];var h =o.offsetHeight;o.style.height=i==1?'200pt':'';if(i==1 &amp;&amp; o.offsetHeight&gt;h)o.style.height=h;"
    sel="0" selold="0"&gt;&lt;b&gt; Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;&lt;input type="Radio" onclick="parentNode.sel=0" name="988984db983549d78652ccd87c368df7"
     checked ID="Radio7" VALUE="Radio7"&gt;Hide&lt;input type="Radio" onclick="parentNode.sel=1" name="988984db983549d78652ccd87c368df7"
     ID="Radio8" VALUE="Radio8"&gt;Scroll&lt;input type="Radio" onclick="parentNode.sel=2" name="988984db983549d78652ccd87c368df7"
     ID="Radio9" VALUE="Radio9"&gt;Full&lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New';display:'none'"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt;
     &amp;lt;summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#008000"&gt; Represents a signed rational number.&lt;/font&gt;&lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
    &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; class&lt;/font&gt; Rational 
    {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt;
      int&lt;/font&gt; numerator;&lt;br&gt;
     &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; denominator;&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Initializes a new instance 
      of the&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see cref=&amp;quot;Rational&amp;quot;/&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;
      class.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param 
      name=&amp;quot;numerator&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The numerator of the 
      rational number.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param 
      name=&amp;quot;denominator&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The denominator of 
      the rational number.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt; Rational(&lt;font color="#0000FF"&gt;int&lt;/font&gt; numerator,&lt;font color="#0000FF"&gt;
      int&lt;/font&gt; denominator) {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;this&lt;/font&gt;.numerator 
      = numerator;&lt;br&gt;
      &lt;font color="#0000FF"&gt;this&lt;/font&gt;.denominator = denominator;&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Gets the numerator of the 
      rational number.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; Numerator 
     {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;get&lt;/font&gt; {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
       numerator;&lt;/div&gt;
      }&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Gets the denominator of the 
      rational number.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; Denominator 
     {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;get&lt;/font&gt; {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
       denominator;&lt;/div&gt;
      }&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Gets the floating-point 
      value of the rational number.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; double&lt;/font&gt; Value {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;get&lt;/font&gt;
      {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt; (&lt;font color="#0000FF"&gt;double&lt;/font&gt;) 
       numerator/(&lt;font color="#0000FF"&gt;double&lt;/font&gt;) denominator;&lt;/div&gt;
      }&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;exclude/&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; override&lt;/font&gt;&lt;font color="#0000FF"&gt;
      string&lt;/font&gt; ToString() {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
      Value.ToString();&lt;/div&gt;
     }&lt;/div&gt;
    }&lt;/div&gt;
   &lt;div style="background-color:#ffffff"&gt;&lt;b&gt; . . .&lt;/b&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- Rational code end --&gt;
  &lt;ul&gt;
   &lt;li&gt;
    URational :&lt;/li&gt;
  &lt;/ul&gt;
  &lt;!-- URational code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid" onclick="var i=this.sel,j;for(j=0;j&lt;3;j++)this.childNodes[2+j*2].checked=j==i;if(i==this.selold)return;var sh=new Array('none',''),o=this.parentNode;j=i==0?0:1;this.selold=i;o.childNodes[1].style.display=sh[j];o.childNodes[2].style.display=sh[1-j];o=o.childNodes[1];var h =o.offsetHeight;o.style.height=i==1?'200pt':'';if(i==1 &amp;&amp; o.offsetHeight&gt;h)o.style.height=h;"
    sel="0" selold="0"&gt;&lt;b&gt; Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;&lt;input type="Radio" onclick="parentNode.sel=0" name="3dcd585a2e8f4c75af9fcecf2d55cb69"
     checked ID="Radio10" VALUE="Radio10"&gt;Hide&lt;input type="Radio" onclick="parentNode.sel=1" name="3dcd585a2e8f4c75af9fcecf2d55cb69"
     ID="Radio11" VALUE="Radio11"&gt;Scroll&lt;input type="Radio" onclick="parentNode.sel=2" name="3dcd585a2e8f4c75af9fcecf2d55cb69"
     ID="Radio12" VALUE="Radio12"&gt;Full&lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New';display:'none'"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt;
     &amp;lt;summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#008000"&gt; Represents an unsigned rational number.&lt;/font&gt;&lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
    &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; class&lt;/font&gt; URational 
    {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt;
      uint&lt;/font&gt; numerator;&lt;br&gt;
     &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; uint&lt;/font&gt; denominator;&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Initializes a new instance 
      of the&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see cref=&amp;quot;Rational&amp;quot;/&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;
      class.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param 
      name=&amp;quot;numerator&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The numerator of the 
      rational number.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param 
      name=&amp;quot;denominator&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The denominator of 
      the rational number.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt; URational(&lt;font color="#0000FF"&gt;uint&lt;/font&gt; 
     numerator,&lt;font color="#0000FF"&gt; uint&lt;/font&gt; denominator) {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;this&lt;/font&gt;.numerator 
      = numerator;&lt;br&gt;
      &lt;font color="#0000FF"&gt;this&lt;/font&gt;.denominator = denominator;&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Gets the numerator of the 
      rational number.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; uint&lt;/font&gt; Numerator 
     {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;get&lt;/font&gt; {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
       numerator;&lt;/div&gt;
      }&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Gets the denominator of the 
      rational number.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; uint&lt;/font&gt; Denominator 
     {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;get&lt;/font&gt; {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
       denominator;&lt;/div&gt;
      }&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Gets the floating-point 
      value of the rational number.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; double&lt;/font&gt; Value {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;get&lt;/font&gt;
      {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt; (&lt;font color="#0000FF"&gt;double&lt;/font&gt;) 
       numerator/(&lt;font color="#0000FF"&gt;double&lt;/font&gt;) denominator;&lt;/div&gt;
      }&lt;/div&gt;
     }&lt;br&gt;
     &lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;exclude/&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; override&lt;/font&gt;&lt;font color="#0000FF"&gt;
      string&lt;/font&gt; ToString() {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
      Value.ToString();&lt;/div&gt;
     }&lt;/div&gt;
    }&lt;/div&gt;
   &lt;div style="background-color:#ffffff"&gt;&lt;b&gt; . . .&lt;/b&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- URational code end --&gt;
  &lt;p&gt;According to the &lt;a href="http://www.exif.org/specifications.html"&gt;Exif 
    specification&lt;/a&gt;, properties may contain arrays of values. Our conversion 
   tool must consequently have the following signature :&lt;/p&gt;
  &lt;!-- Empty FromPropertyItem code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid"&gt;&lt;b&gt;
     Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;
   &lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New'"&gt;&lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt;
     static&lt;/font&gt; Array FromPropertyItem(PropertyItem propertyItem) {}&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- Empty FromPropertyItem code end --&gt;
  &lt;p&gt;The conversion code is quite simple (a &lt;i&gt;switch... case&lt;/i&gt; construct branching 
   on different code depending on the data type).&lt;br /&gt;
   When converting raw data into integers, just take care that Exif properties are 
   stored as big endian values.
  &lt;/p&gt;
  &lt;!-- ExifConvert code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid" onclick="var i=this.sel,j;for(j=0;j&lt;3;j++)this.childNodes[2+j*2].checked=j==i;if(i==this.selold)return;var sh=new Array('none',''),o=this.parentNode;j=i==0?0:1;this.selold=i;o.childNodes[1].style.display=sh[j];o.childNodes[2].style.display=sh[1-j];o=o.childNodes[1];var h =o.offsetHeight;o.style.height=i==1?'200pt':'';if(i==1 &amp;&amp; o.offsetHeight&gt;h)o.style.height=h;"
    sel="1" selold="1"&gt;&lt;b&gt; Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;&lt;input type="Radio" onclick="parentNode.sel=0" name="0e8bd05ef388471bad8d2d72adb58fc3"
     ID="Radio1" VALUE="Radio1"&gt;Hide&lt;input type="Radio" onclick="parentNode.sel=1" name="0e8bd05ef388471bad8d2d72adb58fc3"
     checked ID="Radio2" VALUE="Radio2"&gt;Scroll&lt;input type="Radio" onclick="parentNode.sel=2" name="0e8bd05ef388471bad8d2d72adb58fc3"
     ID="Radio3" VALUE="Radio3"&gt;Full&lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New';Height:200"&gt;&lt;font color="#0000FF"&gt;#region&lt;/font&gt;
    References&lt;br&gt;
    &lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System;&lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System.Drawing.Imaging;&lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System.Runtime.InteropServices;&lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System.Text;&lt;br&gt;
    &lt;br&gt;
    &lt;font color="#0000FF"&gt;#endregion&lt;br&gt;
     &lt;br&gt;
     namespace&lt;/font&gt; ExifNative {&lt;div style="margin-left:20pt"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt;
      &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Summary description for 
      ExifConvert.&lt;/font&gt;&lt;br&gt;
     &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
     &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; sealed&lt;/font&gt;&lt;font color="#0000FF"&gt;
      class&lt;/font&gt; ExifConvert {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;private&lt;/font&gt;
      ExifConvert() {}&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;/font&gt;&lt;br&gt;
      &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Converts a property item to 
       an array of objects.&lt;/font&gt;&lt;br&gt;
      &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;br&gt;
      &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param 
       name=&amp;quot;propertyItem&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The property item 
       to convert.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;br&gt;
      &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;returns&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;An 
       array of&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see cref=&amp;quot;object&amp;quot;/&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;
       items.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;br&gt;
      &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt; Array 
      FromPropertyItem(PropertyItem propertyItem) {&lt;div style="margin-left:20pt"&gt;ExifPropertyType 
       type = (ExifPropertyType) propertyItem.Type;&lt;br&gt;
       &lt;br&gt;
       &lt;font color="#0000FF"&gt;switch&lt;/font&gt; (type) {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;case&lt;/font&gt;
        ExifPropertyType.Raw:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// The value 
          represents raw data (a single byte[] value)&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;return&lt;/font&gt;&lt;font color="#0000FF"&gt; new&lt;/font&gt;&lt;font color="#0000FF"&gt;
          byte&lt;/font&gt;[][] {propertyItem.Value};&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;case&lt;/font&gt; ExifPropertyType.Ascii:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// 
          The value represents an array of strings separated by \0 characters&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;string&lt;/font&gt; stringValue = 
         Encoding.ASCII.GetString(propertyItem.Value, 0, propertyItem.Len - 1);&lt;br&gt;
         &lt;font color="#0000FF"&gt;return&lt;/font&gt; stringValue.Split(&lt;font color="#800000"&gt;'\0'&lt;/font&gt;);&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;case&lt;/font&gt; ExifPropertyType.Byte:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// 
          The value represents an array of bytes&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;return&lt;/font&gt; propertyItem.Value;&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;case&lt;/font&gt; ExifPropertyType.UInt16:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// 
          The value represents an array of unsigned 16-bit integers.&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;int&lt;/font&gt; ushortCount = propertyItem.Len/ushortSize;&lt;br&gt;
         &lt;br&gt;
         &lt;font color="#0000FF"&gt;ushort&lt;/font&gt;[] ushortResult =&lt;font color="#0000FF"&gt; new&lt;/font&gt;&lt;font color="#0000FF"&gt;
          ushort&lt;/font&gt;[ushortCount];&lt;br&gt;
         &lt;font color="#0000FF"&gt;for&lt;/font&gt; (&lt;font color="#0000FF"&gt;int&lt;/font&gt; i = 0; i 
         &amp;lt; ushortCount; i++)&lt;div style="margin-left:20pt"&gt;ushortResult[i] = 
          ReadUInt16(propertyItem.Value, i * ushortSize);&lt;font color="#0000FF"&gt;&lt;/div&gt;
         return&lt;/font&gt; ushortResult;&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;case&lt;/font&gt; ExifPropertyType.Int32:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// 
          The value represents an array of signed 32-bit integers.&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;int&lt;/font&gt; intCount = propertyItem.Len/intSize;&lt;br&gt;
         &lt;br&gt;
         &lt;font color="#0000FF"&gt;int&lt;/font&gt;[] intResult =&lt;font color="#0000FF"&gt; new&lt;/font&gt;&lt;font color="#0000FF"&gt;
          int&lt;/font&gt;[intCount];&lt;br&gt;
         &lt;font color="#0000FF"&gt;for&lt;/font&gt; (&lt;font color="#0000FF"&gt;int&lt;/font&gt; i = 0; i 
         &amp;lt; intCount; i++)&lt;div style="margin-left:20pt"&gt;intResult[i] = 
          ReadInt32(propertyItem.Value, i * intSize);&lt;font color="#0000FF"&gt;&lt;/div&gt;
         return&lt;/font&gt; intResult;&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;case&lt;/font&gt; ExifPropertyType.UInt32:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// 
          The value represents an array of unsigned 32-bit integers.&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;int&lt;/font&gt; uintCount = propertyItem.Len/uintSize;&lt;br&gt;
         &lt;br&gt;
         &lt;font color="#0000FF"&gt;uint&lt;/font&gt;[] uintResult =&lt;font color="#0000FF"&gt; new&lt;/font&gt;&lt;font color="#0000FF"&gt;
          uint&lt;/font&gt;[uintCount];&lt;br&gt;
         &lt;font color="#0000FF"&gt;for&lt;/font&gt; (&lt;font color="#0000FF"&gt;int&lt;/font&gt; i = 0; i 
         &amp;lt; uintCount; i++)&lt;div style="margin-left:20pt"&gt;uintResult[i] = 
          ReadUInt32(propertyItem.Value, i * uintSize);&lt;font color="#0000FF"&gt;&lt;/div&gt;
         return&lt;/font&gt; uintResult;&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;case&lt;/font&gt; ExifPropertyType.Rational:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// 
          The value represents an array of signed rational numbers&lt;/font&gt;&lt;br&gt;
         &lt;font color="#008000"&gt;// Numerator is an Int32 value, denominator a UInt32 value.&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;int&lt;/font&gt; rationalCount = propertyItem.Len/rationalSize;&lt;br&gt;
         &lt;br&gt;
         Rational[] rationalResult =&lt;font color="#0000FF"&gt; new&lt;/font&gt; Rational[rationalCount];&lt;br&gt;
         &lt;font color="#0000FF"&gt;for&lt;/font&gt; (&lt;font color="#0000FF"&gt;int&lt;/font&gt; i = 0; i 
         &amp;lt; rationalCount; i++)&lt;div style="margin-left:20pt"&gt;rationalResult[i] =&lt;font color="#0000FF"&gt;
           new&lt;/font&gt; Rational(&lt;div style="margin-left:20pt"&gt;ReadInt32(propertyItem.Value, 
           i * rationalSize),&lt;br&gt;
           ReadInt32(propertyItem.Value, i * rationalSize + intSize));&lt;font color="#0000FF"&gt;&lt;/div&gt;
         &lt;/div&gt;
         return&lt;/font&gt; rationalResult;&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;case&lt;/font&gt; ExifPropertyType.URational:&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// 
          The value represents an array of signed rational numbers&lt;/font&gt;&lt;br&gt;
         &lt;font color="#008000"&gt;// Numerator and denominator are UInt32 values.&lt;/font&gt;&lt;br&gt;
         &lt;font color="#0000FF"&gt;int&lt;/font&gt; urationalCount = 
         propertyItem.Len/rationalSize;&lt;br&gt;
         &lt;br&gt;
         URational[] urationalResult =&lt;font color="#0000FF"&gt; new&lt;/font&gt; URational[urationalCount];&lt;br&gt;
         &lt;font color="#0000FF"&gt;for&lt;/font&gt; (&lt;font color="#0000FF"&gt;int&lt;/font&gt; i = 0; i 
         &amp;lt; urationalCount; i++)&lt;div style="margin-left:20pt"&gt;urationalResult[i] =&lt;font color="#0000FF"&gt;
           new&lt;/font&gt; URational(&lt;div style="margin-left:20pt"&gt;ReadUInt32(propertyItem.Value, 
           i * urationalSize),&lt;br&gt;
           ReadUInt32(propertyItem.Value, i * urationalSize + uintSize));&lt;font color="#0000FF"&gt;&lt;/div&gt;
         &lt;/div&gt;
         return&lt;/font&gt; urationalResult;&lt;br&gt;
         &lt;br&gt;
        &lt;/div&gt;
        &lt;font color="#0000FF"&gt;default&lt;/font&gt;:&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;&lt;font color="#0000FF"&gt;
          null&lt;/font&gt;;&lt;/div&gt;
       &lt;/div&gt;
       }&lt;/div&gt;
      }&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;#region&lt;/font&gt; Static Fields&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       readonly&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; ushortSize = 
      Marshal.SizeOf(&lt;font color="#0000FF"&gt;typeof&lt;/font&gt; (&lt;font color="#0000FF"&gt;ushort&lt;/font&gt;));&lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       readonly&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; intSize = Marshal.SizeOf(&lt;font color="#0000FF"&gt;typeof&lt;/font&gt;
      (&lt;font color="#0000FF"&gt;int&lt;/font&gt;));&lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       readonly&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; uintSize = Marshal.SizeOf(&lt;font color="#0000FF"&gt;typeof&lt;/font&gt;
      (&lt;font color="#0000FF"&gt;uint&lt;/font&gt;));&lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       readonly&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; rationalSize = 2 * 
      Marshal.SizeOf(&lt;font color="#0000FF"&gt;typeof&lt;/font&gt; (&lt;font color="#0000FF"&gt;int&lt;/font&gt;));&lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       readonly&lt;/font&gt;&lt;font color="#0000FF"&gt; int&lt;/font&gt; urationalSize = 2 * 
      Marshal.SizeOf(&lt;font color="#0000FF"&gt;typeof&lt;/font&gt; (&lt;font color="#0000FF"&gt;uint&lt;/font&gt;));&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;#endregion&lt;br&gt;
       &lt;br&gt;
       #region&lt;/font&gt; Private Helpers&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       ushort&lt;/font&gt; ReadUInt16(&lt;font color="#0000FF"&gt;byte&lt;/font&gt;[] buffer,&lt;font color="#0000FF"&gt;
       int&lt;/font&gt; offset) {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
       (&lt;font color="#0000FF"&gt;ushort&lt;/font&gt;) (&lt;div style="margin-left:20pt"&gt;((&lt;font color="#0000FF"&gt;ushort&lt;/font&gt;) 
        buffer[offset] +&lt;br&gt;
        ((&lt;font color="#0000FF"&gt;ushort&lt;/font&gt;) buffer[offset + 1] &amp;lt;&amp;lt; 8)));&lt;/div&gt;
      &lt;/div&gt;
      }&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       int&lt;/font&gt; ReadInt32(&lt;font color="#0000FF"&gt;byte&lt;/font&gt;[] buffer,&lt;font color="#0000FF"&gt;
       int&lt;/font&gt; offset) {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
       (&lt;font color="#0000FF"&gt;int&lt;/font&gt;) (&lt;div style="margin-left:20pt"&gt;((&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) 
        buffer[offset] +&lt;br&gt;
        ((&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) buffer[offset + 1] &amp;lt;&amp;lt; 8) +&lt;br&gt;
        ((&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) buffer[offset + 2] &amp;lt;&amp;lt; 16) +&lt;br&gt;
        ((&lt;font color="#0000FF"&gt;int&lt;/font&gt;) buffer[offset + 3] &amp;lt;&amp;lt; 24)));&lt;/div&gt;
      &lt;/div&gt;
      }&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
       uint&lt;/font&gt; ReadUInt32(&lt;font color="#0000FF"&gt;byte&lt;/font&gt;[] buffer,&lt;font color="#0000FF"&gt;
       int&lt;/font&gt; offset) {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt;
       (&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) (&lt;div style="margin-left:20pt"&gt;((&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) 
        buffer[offset] +&lt;br&gt;
        ((&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) buffer[offset + 1] &amp;lt;&amp;lt; 8) +&lt;br&gt;
        ((&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) buffer[offset + 2] &amp;lt;&amp;lt; 16) +&lt;br&gt;
        ((&lt;font color="#0000FF"&gt;uint&lt;/font&gt;) buffer[offset + 3] &amp;lt;&amp;lt; 24)));&lt;/div&gt;
      &lt;/div&gt;
      }&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;#endregion&lt;/font&gt;&lt;/div&gt;
     }&lt;/div&gt;
    }&lt;/div&gt;
   &lt;div style="display:none;background-color:#ffffff"&gt;&lt;b&gt; . . .&lt;/b&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- ExifConvert code end --&gt;
  &lt;p&gt;The following code is a sample console application that make use of the code 
   above to load an image and display the content of Exif properties.&lt;/p&gt;
  &lt;!-- Main code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid"&gt;&lt;b&gt;
     Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;
   &lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New'"&gt;[STAThread]&lt;br&gt;
    &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt;&lt;font color="#0000FF"&gt;
     void&lt;/font&gt; Main(&lt;font color="#0000FF"&gt;string&lt;/font&gt;[] args) {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;using&lt;/font&gt;(Image 
     image = Image.FromFile(args[0])) {&lt;div style="margin-left:20pt"&gt;Console.WriteLine(&lt;font color="#800000"&gt;&amp;quot;{0} 
       : {1} properties&amp;quot;&lt;/font&gt;, args[0], image.PropertyItems.Length);&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;foreach&lt;/font&gt; (PropertyItem propertyItem&lt;font color="#0000FF"&gt;
       in&lt;/font&gt; image.PropertyItems) {&lt;div style="margin-left:20pt"&gt;Array result = 
       ExifConvert.FromPropertyItem(propertyItem);&lt;br&gt;
       Console.WriteLine(&lt;font color="#800000"&gt;&amp;quot;Property #{0}, type : {1}, {2} 
        value(s)&amp;quot;&lt;/font&gt;, propertyItem.Id, 
       (ExifPropertyType)propertyItem.Type, result.Length);&lt;br&gt;
       &lt;br&gt;
       &lt;font color="#0000FF"&gt;foreach&lt;/font&gt; (&lt;font color="#0000FF"&gt;object&lt;/font&gt;&lt;font color="#0000FF"&gt;
        value&lt;/font&gt;&lt;font color="#0000FF"&gt; in&lt;/font&gt; result)&lt;div style="margin-left:20pt"&gt;Console.WriteLine(&lt;font color="#800000"&gt;&amp;quot;\t{0}&amp;quot;&lt;/font&gt;,&lt;font color="#0000FF"&gt;
         value&lt;/font&gt;);&lt;br&gt;
       &lt;/div&gt;
       Console.WriteLine();&lt;/div&gt;
      }&lt;/div&gt;
     }&lt;/div&gt;
    }
   &lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- Main code end --&gt;&lt;img src ="http://www.pixvillage.com/blogs/devblog/aggbug/215.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Buz &amp; Skup</dc:creator><title>Exif Properties in .Net - Part 2 : creating new properties</title><link>http://www.pixvillage.com/blogs/devblog/archive/2005/03/27/176.aspx</link><pubDate>Sun, 27 Mar 2005 20:04:00 GMT</pubDate><guid>http://www.pixvillage.com/blogs/devblog/archive/2005/03/27/176.aspx</guid><wfw:comment>http://www.pixvillage.com/blogs/devblog/comments/176.aspx</wfw:comment><comments>http://www.pixvillage.com/blogs/devblog/archive/2005/03/27/176.aspx#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.pixvillage.com/blogs/devblog/comments/commentRss/176.aspx</wfw:commentRss><trackback:ping>http://www.pixvillage.com/blogs/devblog/services/trackbacks/176.aspx</trackback:ping><description>&lt;p&gt;When you manage Exif properties, you commonly have two basic tasks to handle : &lt;i&gt;reading&lt;/i&gt;
   Exif properties (which is quite simple), and &lt;i&gt;writing&lt;/i&gt; Exif properties, 
   which is, in C#, as simple as:&lt;/p&gt;
  &lt;!-- SetPropertyItem code --&gt;
  &lt;div style='BORDER-RIGHT:#c0c0c0 1px solid;BORDER-TOP:#c0c0c0 1px solid;MARGIN-LEFT:10pt;BORDER-LEFT:#c0c0c0 1px solid;MARGIN-RIGHT:2pt;BORDER-BOTTOM:#c0c0c0 1px solid'&gt;&lt;div style="FONT-SIZE:10pt;BORDER-BOTTOM:#c0c0c0 1px solid"&gt;&lt;b&gt;
     Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;
   &lt;/div&gt;
   &lt;div style="FONT-SIZE:15px;OVERFLOW:auto;FONT-FAMILY:'Courier New'"&gt;PropertyItem 
    property = ...;&lt;br&gt;
    Image image = ...;&lt;br&gt;
    &lt;br&gt;
    image.SetPropertyItem(property);&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- SetPropertyItem code end --&gt;
  &lt;p&gt;
   In the code above, the &lt;i&gt;Image&lt;/i&gt; object may have been created from a file, a 
   stream, an existing image, or just from scratch...&lt;br&gt;
   The &lt;i&gt;PropertyItem&lt;/i&gt; may have been retrieved from an image, or... &lt;i&gt;nothing&lt;/i&gt;
   : the &lt;i&gt;System.Drawing.Imaging.PropertyItem&lt;/i&gt; class do not have a public 
   constructor!
  &lt;/p&gt;
  &lt;p&gt;
   In this post, I am describing a workaround that enable to create new &lt;i&gt;PropertyItem&lt;/i&gt;
   objects.
  &lt;/p&gt;
  &lt;p&gt;The method is, in fact, quite simple. It consists in having a small Jpeg image 
   with Exif information embedded in you application, and loading &lt;i&gt;PropertyItem&lt;/i&gt;
   from it when necessary.&lt;/p&gt;
  &lt;p&gt;First, you have to add your Jpeg file (let's call it "&lt;i&gt;property.jpg&lt;/i&gt;") to 
   your project, and mark it as an embedded resource.&lt;/p&gt;
  &lt;ul&gt;
   &lt;li&gt;
   In the Solution Explorer, select the project icon,
   &lt;li&gt;
    In the &lt;i&gt;Project&lt;/i&gt; menu, click the &lt;i&gt;Add an existing item&lt;/i&gt;
   menu,
   &lt;li&gt;
   In the dialog box, choose a valid Jpeg file and click Open; the file does 
   appear in the Solution Explorer,
   &lt;li&gt;
   In the Solution Explorer, select the Jpeg file ,
   &lt;li&gt;
    In the Properties view, set the "&lt;i&gt;Build Action&lt;/i&gt;" property to "&lt;i&gt;Embedded 
     Resource&lt;/i&gt;".&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;The second step is to add a reference on the &lt;i&gt;System.Drawing&lt;/i&gt; assembly to 
   the project, if not present, and to add the following lines at the top of the 
   source file:&lt;/p&gt;
  &lt;!-- Using code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid"&gt;&lt;b&gt;
     Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;
   &lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New'"&gt;&lt;font color="#0000FF"&gt;using&lt;/font&gt;
    System;&lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System.Drawing;&lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System.Drawing.Imaging;&lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System.IO;&lt;br&gt;
    &lt;font color="#0000FF"&gt;using&lt;/font&gt; System.Reflection;&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- Using code end --&gt;
  &lt;p&gt;Now when have to load the image and return the first property item it contains :&lt;/p&gt;
  &lt;!-- CreatePropertyItem code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid"&gt;&lt;b&gt;
     Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;
   &lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New'"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt;
     &amp;lt;summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#008000"&gt; Creates a new property item.&lt;/font&gt;&lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;returns&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;A 
     new instance of the&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see 
     cref=&amp;quot;PropertyItem&amp;quot;/&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt; class.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;br&gt;
    &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt; PropertyItem 
    CreatePropertyImage()&lt;br&gt;
    {&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// Gets the current assembly, 
      retrieves the stream for the resource and loads the associated image.&lt;/font&gt;&lt;br&gt;
     Assembly currentAssembly = Assembly.GetExecutingAssembly();&lt;br&gt;
     &lt;font color="#0000FF"&gt;using&lt;/font&gt;(Stream propertyStream = 
     currentAssembly.GetManifestResourceStream(currentAssembly.GetName().Name + 
     &amp;quot;.&amp;quot; + &amp;quot;property.jpg&amp;quot;))&lt;br&gt;
     &lt;font color="#0000FF"&gt;using&lt;/font&gt;(Image resourceImage = 
     (Image)Image.FromStream(propertyStream))&lt;br&gt;
     {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt; resourceImage.PropertyItems[0];&lt;/div&gt;
     }&lt;/div&gt;
    }
   &lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- CreatePropertyItem code end --&gt;
  &lt;p&gt;The job is almost complete : we can now optimize this code to load the image 
   only once and to return a clean object.&lt;/p&gt;
  &lt;!-- Full code --&gt;
  &lt;div style='margin-left:10pt;margin-right:2pt;border:#c0c0c0 1px solid'&gt;&lt;div style="font-size:10pt;border-bottom:#c0c0c0 1px solid" onclick="var i=this.sel,j;for(j=0;j&lt;3;j++)this.childNodes[2+j*2].checked=j==i;if(i==this.selold)return;var sh=new Array('none',''),o=this.parentNode;j=i==0?0:1;this.selold=i;o.childNodes[1].style.display=sh[j];o.childNodes[2].style.display=sh[1-j];o=o.childNodes[1];var h =o.offsetHeight;o.style.height=i==1?'200pt':'';if(i==1 &amp;&amp; o.offsetHeight&gt;h)o.style.height=h;"
    sel="0" selold="0"&gt;&lt;b&gt; Code &lt;/b&gt;&lt;a href='javascript:' onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;
     Copy &lt;/a&gt;&lt;input type="Radio" onclick="parentNode.sel=0" name="b41da6f38c9a4f58a1a0503274a01439"
     checked ID="Radio1" VALUE="Radio1"&gt;Hide&lt;input type="Radio" onclick="parentNode.sel=1" name="b41da6f38c9a4f58a1a0503274a01439"
     ID="Radio2" VALUE="Radio2"&gt;Scroll&lt;input type="Radio" onclick="parentNode.sel=2" name="b41da6f38c9a4f58a1a0503274a01439"
     ID="Radio3" VALUE="Radio3"&gt;Full&lt;/div&gt;
   &lt;div style="overflow:auto;font-size:15;font-family:'Courier New';display:'none'"&gt;&lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt;
     static&lt;/font&gt; Image propertyImage;&lt;br&gt;
    &lt;br&gt;
    &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt; Image 
    PropertyImage&lt;br&gt;
    {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;get&lt;/font&gt;&lt;br&gt;
     {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;if&lt;/font&gt; (propertyImage==&lt;font color="#0000FF"&gt;null&lt;/font&gt;)&lt;div style="margin-left:20pt"&gt;propertyImage 
       = LoadPropertyImage();&lt;br&gt;
       &lt;font color="#0000FF"&gt;
      &lt;/div&gt;
      return&lt;/font&gt; propertyImage;&lt;/div&gt;
     }&lt;/div&gt;
    }&lt;br&gt;
    &lt;br&gt;
    &lt;font color="#0000FF"&gt;private&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt; Image 
    LoadPropertyImage()&lt;br&gt;
    {&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// Gets the current assembly, 
      retrieves the stream for the resource and loads the associated image.&lt;/font&gt;&lt;br&gt;
     Assembly currentAssembly = Assembly.GetExecutingAssembly();&lt;br&gt;
     &lt;font color="#0000FF"&gt;using&lt;/font&gt;(Stream propertyStream = 
     currentAssembly.GetManifestResourceStream(currentAssembly.GetName().Name + 
     &amp;quot;.&amp;quot; + &amp;quot;property.jpg&amp;quot;))&lt;br&gt;
     &lt;font color="#0000FF"&gt;using&lt;/font&gt;(Image resourceImage = 
     (Image)Image.FromStream(propertyStream))&lt;br&gt;
     {&lt;div style="margin-left:20pt"&gt;&lt;font color="#008000"&gt;// Creates a lightweight (1x1 
       pixel) bitmap with a single, empty exif property item.&lt;/font&gt;&lt;br&gt;
      &lt;font color="#008000"&gt;// This bitmap will remain in memory during the entire 
       application runtime.&lt;/font&gt;&lt;br&gt;
      Image propertyImage =&lt;font color="#0000FF"&gt; new&lt;/font&gt; Bitmap(1, 1);&lt;br&gt;
      PropertyItem propertyItem = resourceImage.PropertyItems[0];&lt;br&gt;
      propertyItem.Id = 0;&lt;br&gt;
      propertyItem.Type = 0;&lt;br&gt;
      propertyItem.Len = 0;&lt;br&gt;
      propertyItem.Value =&lt;font color="#0000FF"&gt; new&lt;/font&gt;&lt;font color="#0000FF"&gt; byte&lt;/font&gt;[0];&lt;br&gt;
      &lt;br&gt;
      propertyImage.SetPropertyItem(propertyItem);&lt;br&gt;
      &lt;br&gt;
      &lt;font color="#0000FF"&gt;return&lt;/font&gt; propertyImage;&lt;/div&gt;
     }&lt;/div&gt;
    }&lt;br&gt;
    &lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#008000"&gt; Creates an empty property item.&lt;/font&gt;&lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;returns&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;A 
     new, empty instance of the&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see 
     cref=&amp;quot;PropertyItem&amp;quot;/&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt; class.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;br&gt;
    &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt; PropertyItem 
    CreatePropertyItem()&lt;br&gt;
    {&lt;div style="margin-left:20pt"&gt;&lt;font color="#0000FF"&gt;return&lt;/font&gt; PropertyImage.PropertyItems[0];&lt;/div&gt;
    }&lt;br&gt;
    &lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#008000"&gt; Creates a new property item having the given 
     id, type and value.&lt;/font&gt;&lt;br&gt;
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;/summary&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param name=&amp;quot;id&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The 
     identifier of the property item.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param name=&amp;quot;type&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The 
     type of value the property item does contain.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param name=&amp;quot;len&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The 
     length of the property value.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;param name=&amp;quot;value&amp;quot;&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;The 
     property value.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/param&amp;gt;&lt;br&gt;
     ///&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;returns&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt;A 
     new, initialized, instance of the&lt;/font&gt;&lt;font color="#808080"&gt; &amp;lt;see 
     cref=&amp;quot;PropertyItem&amp;quot;/&amp;gt;&lt;/font&gt;&lt;font color="#008000"&gt; class.&lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;br&gt;
    &lt;font color="#0000FF"&gt;public&lt;/font&gt;&lt;font color="#0000FF"&gt; static&lt;/font&gt; PropertyItem 
    CreatePropertyItem(&lt;font color="#0000FF"&gt;int&lt;/font&gt; id,&lt;font color="#0000FF"&gt; short&lt;/font&gt;
    type,&lt;font color="#0000FF"&gt; int&lt;/font&gt; len,&lt;font color="#0000FF"&gt; byte&lt;/font&gt;[]&lt;font color="#0000FF"&gt;
     value&lt;/font&gt;)&lt;br&gt;
    {&lt;div style="margin-left:20pt"&gt;PropertyItem property = CreatePropertyItem();&lt;br&gt;
     property.Id = id;&lt;br&gt;
     property.Type = type;&lt;br&gt;
     property.Len = len;&lt;br&gt;
     property.Value =&lt;font color="#0000FF"&gt; value&lt;/font&gt;;&lt;/div&gt;
    }&lt;br&gt;
   &lt;/div&gt;
   &lt;div style="background-color:#ffffff"&gt;&lt;b&gt; . . .&lt;/b&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- Full code end --&gt;
  &lt;p&gt;In the next post, we will convert the raw Exif data buffer (the &lt;i&gt;PropertyItem.Value&lt;/i&gt;) 
   into the native type.&lt;/p&gt;&lt;img src ="http://www.pixvillage.com/blogs/devblog/aggbug/176.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Buz &amp; Skup</dc:creator><title>Managed Gdi Wrapper for Better Performance</title><link>http://www.pixvillage.com/blogs/devblog/archive/2005/03/22/163.aspx</link><pubDate>Tue, 22 Mar 2005 19:04:00 GMT</pubDate><guid>http://www.pixvillage.com/blogs/devblog/archive/2005/03/22/163.aspx</guid><wfw:comment>http://www.pixvillage.com/blogs/devblog/comments/163.aspx</wfw:comment><comments>http://www.pixvillage.com/blogs/devblog/archive/2005/03/22/163.aspx#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.pixvillage.com/blogs/devblog/comments/commentRss/163.aspx</wfw:commentRss><trackback:ping>http://www.pixvillage.com/blogs/devblog/services/trackbacks/163.aspx</trackback:ping><description>The days of Avalon have not come yet and Gdi Plus is surely a nice API to create wonderfull UI whith transparency and gradients, but it has a plumbing caveats : It cannot benefit of graphic cards acceleration.

Let's see how to wrap Gdi gently in Managed Code to take benefit of it...&lt;img src ="http://www.pixvillage.com/blogs/devblog/aggbug/163.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Buz &amp; Skup</dc:creator><title>Exif Properties in .Net - Part 1 : (fast) loading</title><link>http://www.pixvillage.com/blogs/devblog/archive/2005/03/17/159.aspx</link><pubDate>Thu, 17 Mar 2005 11:51:00 GMT</pubDate><guid>http://www.pixvillage.com/blogs/devblog/archive/2005/03/17/159.aspx</guid><wfw:comment>http://www.pixvillage.com/blogs/devblog/comments/159.aspx</wfw:comment><comments>http://www.pixvillage.com/blogs/devblog/archive/2005/03/17/159.aspx#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.pixvillage.com/blogs/devblog/comments/commentRss/159.aspx</wfw:commentRss><trackback:ping>http://www.pixvillage.com/blogs/devblog/services/trackbacks/159.aspx</trackback:ping><description>&lt;P style="TEXT-ALIGN: justify"&gt;In .Net, handling a picture's Exif properties seems, at first sight, to be a very simple job.&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;Since &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;System.Drawing&lt;/SPAN&gt; is only a wrapper around GDI+, loading Exif information from an image file is as simple as the following :&lt;/P&gt;&lt;!-- Sample code --&gt;
&lt;DIV style="BORDER-RIGHT: #c0c0c0 1px solid; BORDER-TOP: #c0c0c0 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #c0c0c0 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #c0c0c0 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #c0c0c0 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt; PropertyItem[] GetExifProperties(&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt; fileName) {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt;(Image image = Image.FromFile(fileName))
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; image.PropertyItems;&lt;/DIV&gt;&lt;/DIV&gt;}&lt;BR&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- End of sample code --&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;Unfortunately, this method requires to load - and validate - all image data in order to access the Exif properties. For instance, if you want to retrieve the thumbnail contained in the Exif properties, you first have to load and uncompress the entire image file.&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;This problem has been workarounded in the .Net Framework 1.1 Service Pack 1, and now you can process as follow :&lt;/P&gt;&lt;!-- Sample code --&gt;
&lt;DIV style="BORDER-RIGHT: #c0c0c0 1px solid; BORDER-TOP: #c0c0c0 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #c0c0c0 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #c0c0c0 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #c0c0c0 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt; PropertyItem[] GetExifProperties(&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt; fileName) {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; (FileStream stream =&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt; FileStream(fileName, FileMode.Open, FileAccess.Read))&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; (Image image = Image.FromStream(stream,
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;&lt;FONT color=#008000&gt;/* useEmbeddedColorManagement = */&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; true&lt;/FONT&gt;,&lt;BR&gt;&lt;FONT color=#008000&gt;/* validateImageData = */&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; false&lt;/FONT&gt;))&lt;FONT color=#0000ff&gt;&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; image.PropertyItems;&lt;/DIV&gt;&lt;/DIV&gt;}&lt;BR&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- End of sample code --&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;However, since there is only a small share of PixVillage users that have the .Net Framework 1.1 Service Pack 1 installed, I eventually have implemented a custom ExifLoader helper class that use Interop to load Exif properties.&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;The first step is to load the image using the GDI+ Flat API and get the Exif properties raw data : &lt;/P&gt;&lt;!-- Sample code --&gt;
&lt;DIV style="BORDER-RIGHT: #c0c0c0 1px solid; BORDER-TOP: #c0c0c0 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #c0c0c0 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #c0c0c0 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #c0c0c0 1px solid" onclick="var i=this.sel,j;for(j=0;j&lt;3;j++)this.childNodes[2+j*2].checked=j==i;if(i==this.selold)return;var sh=new Array('none',''),o=this.parentNode;j=i==0?0:1;this.selold=i;o.childNodes[1].style.display=sh[j];o.childNodes[2].style.display=sh[1-j];o=o.childNodes[1];var h =o.offsetHeight;o.style.height=i==1?'200pt':'';if(i==1 &amp;amp;&amp;amp; o.offsetHeight&gt;h)o.style.height=h;" selold="1" sel="1"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;INPUT id=Radio1 onclick=parentNode.sel=0 type=radio value=Radio1 name=eab1f002b1ce46c08b7a6a77c28de267&gt;Hide&lt;INPUT id=Radio2 onclick=parentNode.sel=1 type=radio CHECKED value=Radio2 name=eab1f002b1ce46c08b7a6a77c28de267&gt;Scroll&lt;INPUT id=Radio3 onclick=parentNode.sel=2 type=radio value=Radio3 name=eab1f002b1ce46c08b7a6a77c28de267&gt;Full&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; HEIGHT: 200px"&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System;&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System.Drawing;&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System.Drawing.Imaging;&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System.IO;&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System.Reflection;&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System.Runtime.InteropServices;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;summary&amp;gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Contains helper methods for loading Exif properties.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; sealed&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; class&lt;/FONT&gt; ExifLoader {&lt;BR&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt; ExifLoader() {}&lt;BR&gt;&lt;FONT color=#808080&gt;&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Retrieves Exif properties from a file.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;param name="fileName"&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;The name of the Exif image file.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/param&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;returns&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;An array of&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;see cref="PropertyItem"/&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt; objects containing the Exif properties.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/returns&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt; PropertyItem[] GetExifProperties(&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt; fileName) {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#008000&gt;// Loads the image file using the GDI+ Flat API&lt;/FONT&gt;&lt;BR&gt;IntPtr imageHandle = IntPtr.Zero;&lt;BR&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (GdipLoadImageFromFile(fileName,&lt;FONT color=#0000ff&gt; out&lt;/FONT&gt; imageHandle)!=0)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;throw&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt; InvalidOperationException();&lt;BR&gt;&lt;FONT color=#0000ff&gt;&lt;/DIV&gt;int&lt;/FONT&gt; count;&lt;BR&gt;&lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; totalSize;&lt;BR&gt;IntPtr data = IntPtr.Zero;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;try&lt;/FONT&gt; {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#008000&gt;// Retrieves the number of properties the image contains&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (GdipGetPropertyCount(imageHandle,&lt;FONT color=#0000ff&gt; out&lt;/FONT&gt; count)!=0)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;throw&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt; InvalidOperationException();&lt;BR&gt;&lt;FONT color=#008000&gt;&lt;/DIV&gt;// Gets the total size, in bytes, of the properties&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (GdipGetPropertySize(imageHandle,&lt;FONT color=#0000ff&gt; out&lt;/FONT&gt; totalSize,&lt;FONT color=#0000ff&gt; ref&lt;/FONT&gt; count)!=0)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;throw&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt; InvalidOperationException();&lt;BR&gt;&lt;FONT color=#008000&gt;&lt;/DIV&gt;// There is no available properties...&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (count == 0 || totalSize == 0)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt; PropertyItem[0];&lt;BR&gt;&lt;FONT color=#008000&gt;&lt;/DIV&gt;// Loads all properties into memory.&lt;/FONT&gt;&lt;BR&gt;data = Marshal.AllocHGlobal(totalSize);&lt;BR&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (GdipGetAllPropertyItems(imageHandle, totalSize, count, data)!=0)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;throw&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt; InvalidOperationException();&lt;BR&gt;&lt;FONT color=#008000&gt;&lt;/DIV&gt;// Convert the properties buffer into an array of PropertyItem objects.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; ExifPropertyItem.ConvertFromMemory(data, count);&lt;/DIV&gt;}&lt;BR&gt;&lt;FONT color=#0000ff&gt;finally&lt;/FONT&gt; {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (data != IntPtr.Zero)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;Marshal.FreeHGlobal(data);&lt;BR&gt;&lt;FONT color=#008000&gt;&lt;/DIV&gt;// Releases the GDI+ image.&lt;/FONT&gt;&lt;BR&gt;GdipDisposeImage(imageHandle);&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; COLOR: #808080; BORDER-BOTTOM: #808080 1px solid"&gt;ExifPropertyItem Helper Class&lt;/SPAN&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;// GDI+ Interop&lt;/FONT&gt;&lt;BR&gt;[DllImport(&lt;FONT color=#800000&gt;"gdiplus.dll"&lt;/FONT&gt;, CharSet=CharSet.Unicode, ExactSpelling=&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;)]&lt;BR&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; extern&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; GdipLoadImageFromFile(&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt; filename,&lt;FONT color=#0000ff&gt; out&lt;/FONT&gt; IntPtr image);&lt;BR&gt;&lt;BR&gt;[DllImport(&lt;FONT color=#800000&gt;"gdiplus.dll"&lt;/FONT&gt;, CharSet=CharSet.Unicode, ExactSpelling=&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;)]&lt;BR&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; extern&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; GdipDisposeImage(IntPtr image);&lt;BR&gt;&lt;BR&gt;[DllImport(&lt;FONT color=#800000&gt;"gdiplus.dll"&lt;/FONT&gt;, CharSet=CharSet.Unicode, ExactSpelling=&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;)]&lt;BR&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; extern&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; GdipGetPropertyCount(IntPtr image,&lt;FONT color=#0000ff&gt; out&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; count);&lt;BR&gt;&lt;BR&gt;[DllImport(&lt;FONT color=#800000&gt;"gdiplus.dll"&lt;/FONT&gt;, CharSet=CharSet.Unicode, ExactSpelling=&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;)]&lt;BR&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; extern&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; GdipGetPropertySize(IntPtr image,&lt;FONT color=#0000ff&gt; out&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; totalSize,&lt;FONT color=#0000ff&gt; ref&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; count);&lt;BR&gt;&lt;BR&gt;[DllImport(&lt;FONT color=#800000&gt;"gdiplus.dll"&lt;/FONT&gt;, CharSet=CharSet.Unicode, ExactSpelling=&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;)]&lt;BR&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; extern&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; GdipGetAllPropertyItems(IntPtr image,&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; totalSize,&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; count, IntPtr buffer);&lt;BR&gt;&lt;/DIV&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;DIV style="DISPLAY: none; BACKGROUND-COLOR: #ffffff"&gt;&lt;B&gt;. . .&lt;/B&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- End of sample code --&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;Then, we have to decode the buffer filled by &lt;FONT face="Courier New"&gt;GdipGetAllPropertyItems&lt;/FONT&gt;. This is done using a private inner class, as follow :&lt;/P&gt;&lt;!-- Sample code --&gt;
&lt;DIV style="BORDER-RIGHT: #c0c0c0 1px solid; BORDER-TOP: #c0c0c0 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #c0c0c0 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #c0c0c0 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #c0c0c0 1px solid" onclick="var i=this.sel,j;for(j=0;j&lt;3;j++)this.childNodes[2+j*2].checked=j==i;if(i==this.selold)return;var sh=new Array('none',''),o=this.parentNode;j=i==0?0:1;this.selold=i;o.childNodes[1].style.display=sh[j];o.childNodes[2].style.display=sh[1-j];o=o.childNodes[1];var h =o.offsetHeight;o.style.height=i==1?'200pt':'';if(i==1 &amp;amp;&amp;amp; o.offsetHeight&gt;h)o.style.height=h;" selold="1" sel="1"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;INPUT id=Radio4 onclick=parentNode.sel=0 type=radio value=Radio4 name=1e209960657449fc85d6ff6c5d6aa1ed&gt;Hide&lt;INPUT id=Radio5 onclick=parentNode.sel=1 type=radio CHECKED value=Radio5 name=1e209960657449fc85d6ff6c5d6aa1ed&gt;Scroll&lt;INPUT id=Radio6 onclick=parentNode.sel=2 type=radio value=Radio6 name=1e209960657449fc85d6ff6c5d6aa1ed&gt;Full&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; HEIGHT: 200px"&gt;&lt;FONT color=#0000ff&gt;#region&lt;/FONT&gt; ExifPropertyItem Helper Class&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;summary&amp;gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Represents an helper class for marshaling Exif property items.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;[StructLayout(LayoutKind.Sequential)]
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; class&lt;/FONT&gt; ExifPropertyItem {&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;// Public members used for marshaling.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; id = 0;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; len = 0;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; short&lt;/FONT&gt; type = 0;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt; IntPtr&lt;FONT color=#0000ff&gt; value&lt;/FONT&gt; = IntPtr.Zero;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Initializes a new instance of the&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;see cref="ExifPropertyItem"/&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt; class.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;remarks&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;Used only by the&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;see cref="Marshal.PtrToStructure"/&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt; method.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/remarks&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt; ExifPropertyItem() {}&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Gets the value of the property.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; byte&lt;/FONT&gt;[] Value {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;get&lt;/FONT&gt; {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#0000ff&gt;byte&lt;/FONT&gt;[] buffer =&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; byte&lt;/FONT&gt;[len];&lt;BR&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (len &amp;gt; 0)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;Marshal.Copy(&lt;FONT color=#0000ff&gt;value&lt;/FONT&gt;, buffer, 0, len);&lt;FONT color=#0000ff&gt;&lt;/DIV&gt;return&lt;/FONT&gt; buffer;&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Converts a buffer into an array of PropertyItem objects.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;param name="propertyData"&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;The properties data buffer.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/param&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;param name="count"&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;The number of properties in the buffer.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/param&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;returns&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;An array of&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;see cref="PropertyItem"/&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt; objects.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/returns&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt; PropertyItem[] ConvertFromMemory(IntPtr propertyData,&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; count) {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;PropertyItem[] itemArray =&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt; PropertyItem[count];&lt;BR&gt;&lt;FONT color=#0000ff&gt;for&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; i = 0; i &amp;lt; count; i++) {
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;&lt;FONT color=#008000&gt;// Marshals the buffer into a ExifPropertyItem structure.&lt;/FONT&gt;&lt;BR&gt;ExifPropertyItem item = (ExifPropertyItem)Marshal.PtrToStructure(propertyData,&lt;FONT color=#0000ff&gt; typeof&lt;/FONT&gt;(ExifPropertyItem));&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;// Creates the PropertyItem from the data.&lt;/FONT&gt;&lt;BR&gt;itemArray[i] = Create(item.type,&amp;nbsp;&amp;nbsp;item.id, item.len, item.Value);&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;// Seek to next property.&lt;/FONT&gt;&lt;BR&gt;propertyData = (IntPtr)(((&lt;FONT color=#0000ff&gt;long&lt;/FONT&gt;)propertyData) + Marshal.SizeOf(&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(ExifPropertyItem)));&lt;/DIV&gt;}&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; itemArray;&lt;/DIV&gt;}&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Creates a PropertyItem from its components.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;param name="type"&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;The property type.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/param&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;param name="tag"&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;The property tag.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/param&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;param name="len"&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;The length of the property.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/param&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;param name="value"&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;The property value.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/param&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#808080&gt;///&lt;/FONT&gt;&lt;FONT color=#808080&gt; &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; static&lt;/FONT&gt; PropertyItem Create(&lt;FONT color=#0000ff&gt;short&lt;/FONT&gt; type,&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; tag,&lt;FONT color=#0000ff&gt; int&lt;/FONT&gt; len,&lt;FONT color=#0000ff&gt; byte&lt;/FONT&gt;[]&lt;FONT color=#0000ff&gt; value&lt;/FONT&gt;){
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;PropertyItem item;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;// Loads a PropertyItem from a Jpeg image stored in the assembly as a resource.&lt;/FONT&gt;&lt;BR&gt;Assembly assembly = Assembly.GetExecutingAssembly();&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt;(Stream emptyBitmapStream = assembly.GetManifestResourceStream(&lt;FONT color=#800000&gt;"ExifLoader.empty.jpg"&lt;/FONT&gt;))&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt;(Image empty = Image.FromStream(emptyBitmapStream))
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;item = empty.PropertyItems[0];&lt;BR&gt;&lt;FONT color=#008000&gt;&lt;/DIV&gt;// Copies the data to the property item.&lt;/FONT&gt;&lt;BR&gt;item.Type = type;&lt;BR&gt;item.Len = len;&lt;BR&gt;item.Id = tag;&lt;BR&gt;item.Value =&lt;FONT color=#0000ff&gt; new&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; byte&lt;/FONT&gt;[&lt;FONT color=#0000ff&gt;value&lt;/FONT&gt;.Length];&lt;BR&gt;&lt;FONT color=#0000ff&gt;value&lt;/FONT&gt;.CopyTo(item.Value, 0);&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; item;&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;#endregion&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV style="DISPLAY: none; BACKGROUND-COLOR: #ffffff"&gt;&lt;B&gt;. . .&lt;/B&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- End of sample code --&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;Note that in the class above, we load a jpeg file from resources into memory. This file is named "empty.jpg" but the resource is referenced as "ExifLoader.empty.jpg" since "ExifLoader" is the name of the assembly.&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;Since the &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;PropertyItem&lt;/SPAN&gt; class does not provide a public initializer to create a property "from scratch", we have to use an existing property item.&lt;/P&gt;&lt;!-- End of article --&gt;&lt;img src ="http://www.pixvillage.com/blogs/devblog/aggbug/159.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>