static DefaultImage getImage(string path) { var ii = new DefaultImage(); Image theImage = new Bitmap(path); // Get the PropertyItems property from image. PropertyItem[] propItems = theImage.PropertyItems; var encoding = new UTF8Encoding(); foreach (PropertyItem propItem in propItems) { //if (propItem.Type == 3) // continue; string val = encoding.GetString(propItem.Value); if (propItem.Type == 1) { val = Encoding.Unicode.GetString(propItem.Value); } val = val.Replace("\0", ""); switch (propItem.Id) { case (int)EXIFProperty.Title: try { ii.Priority = Convert.ToDouble(val); } catch { ii.Priority = -1.0; } break; case (int)EXIFProperty.Author: ii.Author = val; break; case (int)EXIFProperty.Subject: ii.Subject = val; break; case (int)EXIFProperty.Rating: ii.rating = BitConverter.ToInt16(propItem.Value, 0); break; } } return(ii); }
static DefaultImage getImage(string path) { var ii = new DefaultImage(); Image theImage = new Bitmap(path); // Get the PropertyItems property from image. PropertyItem[] propItems = theImage.PropertyItems; var encoding = new UTF8Encoding(); foreach (PropertyItem propItem in propItems) { //if (propItem.Type == 3) // continue; string val = encoding.GetString(propItem.Value); if (propItem.Type == 1) val = Encoding.Unicode.GetString(propItem.Value); val = val.Replace("\0", ""); switch (propItem.Id) { case (int)EXIFProperty.Title: try { ii.Priority = Convert.ToDouble(val); } catch { ii.Priority = -1.0; } break; case (int)EXIFProperty.Author: ii.Author = val; break; case (int)EXIFProperty.Subject: ii.Subject = val; break; case (int)EXIFProperty.Rating: ii.rating = BitConverter.ToInt16(propItem.Value, 0); break; } } return ii; }