C#如何修改Image类型的File的Property

本文介绍如何在C#中修改Image类型的文件属性,特别针对IGD+错误提出了解决方法。作者通过探索和实践,将不同property的值转换为枚举,方便赋值,虽然代码不完美,但可供参考。欢迎对不足之处提出改进意见。
摘要由CSDN通过智能技术生成

最近在弄一个要set image类型fileproperty的方法,经过了几天的探索,终于找到了对应的办法,可以解决IGD+错误的问题,干了一些力气活,把每种property对应的value的值取到,然后设置成了一些枚举,通过转化能直接赋值,有需要的可以拿走,算是做了一些贡献,本文只是提供了一种办法,并不是很完美的代码,如果有能够改进或者错误的地方希望大神们指出

   public static void SetImagePropertyValue(FileInfo fileinfo, int propertyid,
            object value, ImagePropertyTagValueTypes type)
        {
            //Also can use Bitmap
            //http://stackoverflow.com/questions/15231161/value-of-image-property-c
            Image image = Image.FromFile(fileinfo.FullName);           
            byte[] data = null;
            if ((short)type == 2)
            {
                switch (propertyid)
                {
                    case PropertyTagDateTaken:
                        DateTime tempvalue = (DateTime)value;
                        data = ConvertDateTimeValue(tempvalue);
                        break;
                    default:
                        string tempValue = (string)value;
                        data = Encoding.ASCII.GetBytes(tempValue);
                        break;
                }
            }
            if ((short)type == 3)
            {
                switch (propertyid)
                {
                    case PropertyTagRating:
                        data = ConvertRatingValue(value);
                        break;
                    default:
                        int tampa = (int)value;
                        UInt16 tempvalue = (UInt16)tampa;
                        data = ConvertInt16ToByteArry(tempval
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值