달력

42024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

'EXIF 수정'에 해당되는 글 1건

  1. 2011.12.08 [ASP.NET C#]이미지 메타태그 값 수정하기 / keyword, comment / EXIF
php 로 EXIF의 keyword 값(이미지 정보중 태그 값) 을 수정하려다가 포기하고 C#으로 만들어 봤다...

몇가지 사이트에서 정보를 얻어서 했지만 자꾸 문제가 발생...
byte 단위로 데이터 읽어가면서 테스트 해서 겨우 성공..

  protected void Page_Load(object sender, EventArgs e)
        {
 //* 특정 이미지 파일을 읽어와서 이미지의 EXIF 정보 중 40094(keyword) 를 화면에 출력함. *//
            System.Drawing.Image theImage = new Bitmap(@"D:\\photo\\DSC02787.JPG");   

            System.Drawing.Imaging.PropertyItem[] propItems = theImage.PropertyItems;
            foreach (System.Drawing.Imaging.PropertyItem items in propItems)
            {
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
//                string value = encoding.GetString(items.Value);
                if (items.Id == 40094)
                {   
                    Response.Write(items.Type + " : " + items.Id + " = " + items.Value.ToString() + "(len : " + items.Len + ")");
                   // for (int i = 0; i < items.Value.Length; i++) Response.Write(items.Value[i] + "<br>");
                }
            }
            theImage.Dispose();
// 특정 이미지에 keyword 값을 수정하여 이미지를 새로 저장
            WriteNewDescriptionInImage(@"d:\\photo\\DSC02787.JPG", "지혜님짱!!;이쁜이;사랑스러워");
        }

        private static ImageCodecInfo GetEncodeInfo(string mimeType)
        {
            int j;
            ImageCodecInfo[] encoders;
            encoders = ImageCodecInfo.GetImageEncoders();
            for (j = 0; j < encoders.Length; j++)
            {
                if (encoders[j].MimeType == mimeType)
                    return encoders[j];
            }
            return null;
        }

        private void WriteNewDescriptionInImage(string FileName, string NewKeywords)
        {
            System.Drawing.Image pic;
            PropertyItem[] PropertyItems;
            byte[] bKeywords = new Byte[NewKeywords.Length];

            string FileNameTemp;
            System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;
            EncoderParameters EncParmas = new EncoderParameters(1);
            EncoderParameter EncParam;
            ImageCodecInfo CodenInfo = GetEncodeInfo("image/jpeg");
// 여기가 중요함 keyword 의 경우 unicode로 읽어야 함... comment 의 경우  ASCII나 UTF8로 읽어야 함. 
            bKeywords = Encoding.Unicode.GetBytes(NewKeywords);

            pic = System.Drawing.Image.FromFile(FileName);
            PropertyItems = pic.PropertyItems;
            foreach (PropertyItem item in PropertyItems)
            {
                if (item.Id == 40094)
                {
                    item.Value = bKeywords;
                    item.Len = bKeywords.Length;
                    pic.SetPropertyItem(item);
                }
            }

            FileNameTemp = FileName + ".temp";  // 파일명 + .temp로 새로 저장...
            EncParam = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);
            EncParmas.Param[0] = EncParam;

            pic.Save(FileNameTemp, CodenInfo, EncParmas);
            pic.Dispose();
            pic = null;
            GC.Collect();
        }

'프로그래밍 > C#' 카테고리의 다른 글

[C#]byte[] 데이터 암호화  (0) 2012.08.31
BinaryWriter pointer 사용(seek)  (0) 2012.08.06
[C#] DataGridViewRow 복사  (0) 2010.07.05
[C#] MessageBox의 기능  (1) 2010.07.05
[C#] DataGridView  (0) 2010.07.02
Posted by SadDev
|