为什么我的自定义PropertyItem不能够被拉出的形象? [英] Why is my custom PropertyItem not able to be pulled out of the Image?

查看:124
本文介绍了为什么我的自定义PropertyItem不能够被拉出的形象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我已经在图像中创造,并存储一些值的自定义PropertyItem。我敢肯定,它的正确存放,因为新的图像将扩大规模,(这取决于我有多大使字符串)。

I have a custom PropertyItem that I've "created" and stored some values in within an image. I'm positive that it's correctly storing it because the new image will increase in size, (depending on how big I make the string).

- [问题是底部] -

--[Question is at the bottom]--

这里的code中,我把PropertyItem到图像。

Here's the code in which I put the PropertyItem into the image.

Bitmap bmp = new Bitmap(image); //image is of type Image
string s = "Hello there";
var pi = createPropertyItem();
pi.Id = 40091;
pi.Len = s.Length+1; //don't worry too much about this - this is a test case,
                     //not the real types and lengths. If I put an error in here,
                     //it's not what's making it error out elsewhere. :)
pi.Type = 2;
pi.Value = s;
bmp.SetPropertyItem(pi);

bmp.Save("image.jpg", bmp.RawFormat);//is this actually saving the PropertyItems
                                     //into the file, "image.jpg"?

不管怎么说,我无法在其他地方 - 我需要从图像中提取PropertyItem价值。但是:

Anyways, I'm having trouble elsewhere - I need to extract the value from the PropertyItem of the image. However:

Bitmap thing = new Bitmap("image.jpg"); // is this the problem code?
String newString = getStringOut(thing);

/////////////////further down in the program//////////////////////////

public String getStringOut(Image image)
{
    var x = image.GetPropertyItem(40091); //this fails because the PropertyItem
                                          //is not in this image.
    string s = x.Value;
}

我的问题是:既然PropertyItem是中保存的图像中(至少它似乎是,因为文件的大小变大的时间越长,我把​​字符串),为什么它没有被我的方法访问,( getStringOut),当我回去和保存的图像尝试和检索PropertyItem?当我初始化新的位图,它是不拉的EXIF数据由于某种原因?

My question is: since the PropertyItem is in the image that's saved (at least it appears to be, since the file's size gets larger the longer the string I put in), why is it NOT being accessed by my method, (getStringOut), when I go back and try and retrieve the PropertyItem from the saved image? When I initialize the new Bitmap, is it not pulling the EXIF data for some reason?

推荐答案

请参阅链接<一个href=\"http://stackoverflow.com/questions/1050936/resize-an-image-and-keeping-metadata-property-item\">here.事实证明,我行code与评论: //就是这个问题code 问题$ C? $ C,因为这是剥出的元数据。

See link here. Turns out that my line of code with the comment: // is this the problem code? is the problem code, because this is stripping out the metadata.

这篇关于为什么我的自定义PropertyItem不能够被拉出的形象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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