「作成」して画像内にいくつかの値を保存したカスタムPropertyItemがあります。新しい画像のサイズが大きくなるため、正しく保存されていると確信しています(文字列の大きさによって異なります)。
-[質問は一番下にあります]-
PropertyItemを画像に配置したコードは次のとおりです。
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から値を抽出する必要があります。でも:
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データがプルされませんか?