Exemplo n.º 1
0
        private void SetJPG(JPGExif jpgExif)
        {
            this.dblProList.Items.Clear();
            this.dblProList.Columns.Clear();
            ColumnHeader property = new ColumnHeader();
            ColumnHeader value = new ColumnHeader();
            property.Text = "属性";
            value.Text = "值";
            property.Width = 80;
            value.Width = 120;

            this.dblProList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            property,
            value});

            ListViewItem[] items = new ListViewItem[10];
            items[0] = new ListViewItem(new string[] {
            "相机制造商", ""});
            items[1] = new ListViewItem(new string[] {
            "相机型号", ""});
            items[2] = new ListViewItem(new string[] {
            "拍摄时间", ""});
            items[3] = new ListViewItem(new string[] {
            "光圈值", ""});
            items[4] = new ListViewItem(new string[] {
            "曝光时间", ""});
            items[5] = new ListViewItem(new string[] {
            "ISO速度", ""});
            items[6] = new ListViewItem(new string[] {
            "闪光灯", ""});
            items[7] = new ListViewItem(new string[] {
            "焦距", ""});
            items[8] = new ListViewItem(new string[] {
            "宽度", ""});
            items[9] = new ListViewItem(new string[] {
            "高度", ""});

            this.pnlPic.Visible = true;
            if (this.picPreview.Image != null)
                this.picPreview.Image.Dispose();
            this.dblProList.Items.AddRange(items);

            this.dblProList.Items[0].SubItems[1].Text = jpgExif.Maker;
            this.dblProList.Items[1].SubItems[1].Text = jpgExif.Model;
            this.dblProList.Items[2].SubItems[1].Text = jpgExif.ShootingTime;
            this.dblProList.Items[3].SubItems[1].Text = jpgExif.F_Number;
            this.dblProList.Items[4].SubItems[1].Text = jpgExif.ExposureTime;
            this.dblProList.Items[5].SubItems[1].Text = jpgExif.ISO;
            this.dblProList.Items[6].SubItems[1].Text = jpgExif.FlashLamp;
            this.dblProList.Items[7].SubItems[1].Text = jpgExif.FocalLength;
            this.dblProList.Items[8].SubItems[1].Text = jpgExif.Width.ToString();
            this.dblProList.Items[9].SubItems[1].Text = jpgExif.Height.ToString();
            this.picPreview.Image = jpgExif.PicPreview;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取JPGExif信息
        /// </summary>
        /// <param name="fullName">文件全名</param>
        /// <returns>JPGExif</returns>
        public static JPGExif GetJPGExif(string fullName)
        {
            JPGExif info = new JPGExif();
            Image img;

            try
            {
                img = Image.FromFile(fullName); //建立新的图像
            }
            catch
            {
                img = null;
                return info;
            }
            PropertyItem[] pt = img.PropertyItems;//获取图片中的exif 信息 ,此时该信息是数组
            info.PicPreview = img;
            info.Width = img.Width;
            info.Height = img.Height;
            for (int i = 0; i < pt.Length; i++)
            {
                PropertyItem p = pt[i];
                switch (pt[i].Id)
                {
                    // 设备制造商
                    case 0x010F:
                        info.Maker = System.Text.ASCIIEncoding.ASCII.GetString(p.Value);
                        break;
                    // 设备型号
                    case 0x0110:
                        info.Model = GetValueOfType2(p.Value);
                        break;
                    // 拍照时间
                    case 0x0132:
                        info.ShootingTime = GetValueOfType2(p.Value);
                        break;
                    // 曝光时间
                    case 0x829A:
                        info.ExposureTime = GetValueOfType5(p.Value);
                        break;
                    // ISO
                    case 0x8827:
                        info.ISO = GetValueOfType3(p.Value);
                        break;
                    //相片的焦距
                    case 0x920a:
                        info.FocalLength = GetValueOfType5A(p.Value);
                        break;
                    //相片的光圈值
                    case 0x829D:
                        info.F_Number = GetValueOfType5A(p.Value);
                        break;
                    //闪光灯
                    case 0x9209:
                        info.FlashLamp = GetValueOfType3(p.Value);
                        break;
                    default:
                        break;
                }
            }
            return info;
        }