Ejemplo n.º 1
0
    private void Update()
    {
      if (m_pTexture != null)
      {
        m_pTexture.Dispose();
      }

      int iRotate = PictureDatabase.GetRotation(FileName);

      m_pTexture = Util.Picture.Load(FileName, iRotate, 1024, 1024, true, false, out m_iTextureWidth,
                                     out m_iTextureHeight);

      lblCameraModel.Label = string.Empty;
      lblDateTakenLabel.Label = string.Empty;
      lblEquipmentMake.Label = string.Empty;
      lblExposureCompensation.Label = string.Empty;
      lblExposureTime.Label = string.Empty;
      lblFlash.Label = string.Empty;
      lblFstop.Label = string.Empty;
      lblImgDimensions.Label = string.Empty;
      lblImgTitle.Label = string.Empty;
      lblMeteringMode.Label = string.Empty;
      lblResolutions.Label = string.Empty;
      lblShutterSpeed.Label = string.Empty;
      lblViewComments.Label = string.Empty;

      using (ExifMetadata extractor = new ExifMetadata())
      {
        ExifMetadata.Metadata metaData = extractor.GetExifMetadata(FileName);

        lblCameraModel.Label = metaData.CameraModel.DisplayValue;
        lblDateTakenLabel.Label = metaData.DatePictureTaken.DisplayValue;
        lblEquipmentMake.Label = metaData.EquipmentMake.DisplayValue;
        lblExposureCompensation.Label = metaData.ExposureCompensation.DisplayValue;
        lblExposureTime.Label = metaData.ExposureTime.DisplayValue;
        lblFlash.Label = metaData.Flash.DisplayValue;
        lblFstop.Label = metaData.Fstop.DisplayValue;
        lblImgDimensions.Label = metaData.ImageDimensions.DisplayValue;
        lblImgTitle.Label = Path.GetFileNameWithoutExtension(FileName);
        lblMeteringMode.Label = metaData.MeteringMode.DisplayValue;
        lblResolutions.Label = metaData.Resolution.DisplayValue;
        lblShutterSpeed.Label = metaData.ShutterSpeed.DisplayValue;
        lblViewComments.Label = metaData.ViewerComments.DisplayValue;

        imgPicture.IsVisible = false;
      }
      if (File.Exists(FileName))
      {
        GUIPropertyManager.SetProperty("#selectedthumb", FileName);
      }
      else
      {
        GUIPropertyManager.SetProperty("#selectedthumb", string.Empty);
      }
    }
 private bool GetExifDetails(string strPicture, ref int iRotation, ref string strDateTaken)
 {
   using (ExifMetadata extractor = new ExifMetadata())
   {
     ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPicture);
     try
     {
       string picExifDate = metaData.DatePictureTaken.DisplayValue;
       if (!String.IsNullOrEmpty(picExifDate))
         // If the image contains a valid exif date store it in the database, otherwise use the file date
       {
         DateTime dat;
         DateTime.TryParseExact(picExifDate, "G", Thread.CurrentThread.CurrentCulture, DateTimeStyles.None, out dat);
         strDateTaken = dat.ToString("yyyy-MM-dd HH:mm:ss");
         if (_useExif)
         {
           iRotation = EXIFOrientationToRotation(Convert.ToInt32(metaData.Orientation.Hex));
         }
         return true;
       }
     }
     catch (FormatException ex)
     {
       Log.Error("PictureDatabaseSqlLite: Exif date conversion exception err:{0} stack:{1}", ex.Message,
                 ex.StackTrace);
     }
   }
   return false;
 }
Ejemplo n.º 3
0
    public DateTime GetDateTaken(string strPicture)
    {
      string strSQL = "";
      try
      {
        string strPic = strPicture;
        DatabaseUtility.RemoveInvalidChars(ref strPic);

        strSQL = String.Format("select * from tblPicture where strFile like '{0}'", strPic);
        using (SqlCommand cmd = _connection.CreateCommand())
        {
          cmd.CommandType = CommandType.Text;
          cmd.CommandText = strSQL;
          using (SqlDataReader reader = cmd.ExecuteReader())
          {
            if (reader.Read())
            {
              DateTime dtDateTime = (DateTime)reader["strDateTaken"];
              reader.Close();
              return dtDateTime;
            }
            reader.Close();
          }
        }
        AddPicture(strPicture, -1);
        string strDateTime;
        using (ExifMetadata extractor = new ExifMetadata())
        {
          ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPic);
          strDateTime = DateTime.Parse(metaData.DatePictureTaken.DisplayValue).ToString("yyyy-MM-dd HH:mm:ss");
        }
        if (strDateTime != string.Empty && strDateTime != "")
        {
          DateTime dtDateTime = DateTime.ParseExact(strDateTime, "yyyy-MM-dd HH:mm:ss", new CultureInfo(""));
          return dtDateTime;
        }
        else
        {
          return DateTime.MinValue;
        }
      }
      catch (Exception ex)
      {
        Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
      }
      return DateTime.MinValue;
    }
Ejemplo n.º 4
0
    public int AddPicture(string strPicture, int iRotation)
    {
      // Continue only if it's a picture files
      if (!Util.Utils.IsPicture(strPicture))
        return -1;

      if (strPicture == null)
      {
        return -1;
      }
      if (strPicture.Length == 0)
      {
        return -1;
      }
      lock (typeof (PictureDatabase))
      {
        string strSQL = "";
        try
        {
          string strPic = strPicture;
          DatabaseUtility.RemoveInvalidChars(ref strPic);

          strSQL = String.Format("select * from tblPicture where strFile like '{0}'", strPic);
          using (SqlCommand cmd = _connection.CreateCommand())
          {
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = strSQL;
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
              if (reader.Read())
              {
                int id = (int)reader["idPicture"];
                reader.Close();
                return id;
              }
              reader.Close();
            }
          }

          //Changed mbuzina
          DateTime dateTaken = DateTime.Now;
          using (ExifMetadata extractor = new ExifMetadata())
          {
            ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPic);
            try
            {
              DateTimeFormatInfo dateTimeFormat = new DateTimeFormatInfo();
              dateTimeFormat.ShortDatePattern = "yyyy:MM:dd HH:mm:ss";

              dateTaken = DateTime.ParseExact(metaData.DatePictureTaken.DisplayValue, "d", dateTimeFormat);
            }
            catch (Exception) {}
            // Smirnoff: Query the orientation information
            //						if(iRotation == -1)
            iRotation = EXIFOrientationToRotation(Convert.ToInt32(metaData.Orientation.Hex));
          }
          strSQL = String.Format("insert into tblPicture (strFile, iRotation, strDateTaken) values('{0}',{1},'{2}')",
                                 strPic, iRotation, dateTaken);
          return SqlServerUtility.InsertRecord(_connection, strSQL);
        }
        catch (Exception ex)
        {
          Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
        }
        return -1;
      }
    }
Ejemplo n.º 5
0
    public int GetRotation(string strPicture)
    {
      // Continue only if it's a picture files
      if (!Util.Utils.IsPicture(strPicture))
        return -1;

      string strSQL = "";
      try
      {
        string strPic = strPicture;
        int iRotation;
        DatabaseUtility.RemoveInvalidChars(ref strPic);

        strSQL = String.Format("select * from tblPicture where strFile like '{0}'", strPic);
        using (SqlCommand cmd = _connection.CreateCommand())
        {
          cmd.CommandType = CommandType.Text;
          cmd.CommandText = strSQL;
          using (SqlDataReader reader = cmd.ExecuteReader())
          {
            if (reader.Read())
            {
              iRotation = (int)reader["iRotation"];
              reader.Close();
              return iRotation;
            }
            reader.Close();
          }
        }

        ExifMetadata extractor = new ExifMetadata();
        ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPicture);
        iRotation = EXIFOrientationToRotation(Convert.ToInt32(metaData.Orientation.Hex));

        AddPicture(strPicture, iRotation);
        return 0;
      }
      catch (Exception ex)
      {
        Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
      }
      return 0;
    }