图像属性的值(C#) [英] Value of image property (C#)

查看:463
本文介绍了图像属性的值(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解决不断变化的价值ImageDescription位图对象的问题。要为文件添加描述。搜索相关主题,我还没有找到一个解决方案。

I'm trying to solve the problem of changing the value ImageDescription for the Bitmap object. To add a description for the file. Searching the related topics, I have not found a solution.

我的code:

public Bitmap ImageWithComment(Bitmap image)
{
   string filePath = @"C:\1.jpg";
   var data = Encoding.UTF8.GetBytes("my comment"); 
   var propItem = image.PropertyItems.FirstOrDefault();
   propItem.Type = 2;
   propItem.Id = 40092;
   propItem.Len = data.Length;
   propItem.Value = data;
   image.SetPropertyItem(propItem);
   image.Save(filePath);
   return image;
}

但随着新评论形象不要在文件夹中保存((请帮我

But image with new comment dont save in folder(( Please help me

推荐答案

据的 MSDN - 你必须使用正确的int值属性标记的编号

According to MSDN - Property Tags you have to use the proper int value for the Id

样品

 using (var image = new Bitmap(@"C:\Desert.jpg"))
            {
                string filePath = @"C:\Desertcopy.jpg";
                var data = Encoding.UTF8.GetBytes("my comment");
                var propItem = image.PropertyItems.FirstOrDefault();
                propItem.Type = 2;
                propItem.Id = 0x010E; // <-- Image Description
                propItem.Len = data.Length;
                propItem.Value = data;
                image.SetPropertyItem(propItem);
                image.Save(filePath);
            }

使用从MSDN以下数

using the following number from MSDN

运行code后,你可以看到它如何影响图像

after running the code, you can see how it affected the image

之前

之后

这篇关于图像属性的值(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆