2

「作成」して画像内にいくつかの値を保存したカスタム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データがプルされませんか?

4

2 に答える 2

0

こちらのリンクをご覧ください。コメント付きの私のコード行は// is this the problem code? メタデータを削除しているため、問題のあるコードであることがわかります。

于 2013-01-02T14:36:37.770 に答える
0

この方法を試しましたか?基本的に、プロパティアイテムをコピーし、設定する前にそのIDを変更しますか?

また、この質問を確認することをお勧めします。作成者は自分のプロパティアイテムを取得しようとはしません(または自分自身を試みているとは説明しません)が、(彼の回答では)あなたとは異なるテクニックとPropertyItemプロパティ値を使用します。

于 2012-12-21T21:11:23.913 に答える