c语言如何添加很多信息,使用C语言添加exif信息

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

private   void   WriteNewDescriptionInImage(string   Filename,string   NewDescription)

{

Image   Pic;

PropertyItem[]   PropertyItems;

byte[]   bDescription=new   Byte[NewDescription.Length];

int   i;

string   FilenameTemp;

Encoder   Enc=Encoder.Transformation;

EncoderParameters   EncParms=new   EncoderParameters(1);

EncoderParameter   EncParm;

ImageCodecInfo   CodecInfo=GetEncoderInfo("image/jpeg");

//   copy   description   into   byte   array

for   (i=0;i

//   load   the   image   to   change

Pic=Image.FromFile(Filename);

//   put   the   new   description   into   the   right   property   item

PropertyItems=Pic.PropertyItems;

PropertyItems[0].Id=0x010e;   //   0x010e   as   specified   in   EXIF   standard

PropertyItems[0].Type=2;

PropertyItems[0].Len=NewDescription.Length;

PropertyItems[0].Value=bDescription;

Pic.SetPropertyItem(PropertyItems[0]);

//   we   cannot   store   in   the   same   image,   so   use   a   temporary   image   instead

FilenameTemp=Filename+".temp";

//   for   lossless   rewriting   must   rotate   the   image   by   90   degrees!

EncParm=new   EncoderParameter(Enc,(long)EncoderValue.TransformRotate90);

EncParms.Param[0]=EncParm;

//   now   write   the   rotated   image   with   new   description

Pic.Save(FilenameTemp,CodecInfo,EncParms);

//   for   computers   with   low   memory   and   large   pictures:   release   memory   now

Pic.Dispose();

Pic=null;

GC.Collect();

//   delete   the   original   file,   will   be   replaced   later

System.IO.File.Delete(Filename);

//   now   must   rotate   back   the   written   picture

Pic=Image.FromFile(FilenameTemp);

EncParm=new   EncoderParameter(Enc,(long)EncoderValue.TransformRotate270);

EncParms.Param[0]=EncParm;

Pic.Save(Filename,CodecInfo,EncParms);

//   release   memory   now

Pic.Dispose();

Pic=null;

GC.Collect();

//   delete   the   temporary   picture

System.IO.File.Delete(FilenameTemp);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值