Zapisz bitmapę do png z danymi medata wpf c # [duplikat]

Dec 30 2020

Muszę zapisać bitmapę do jpg z medatą, taką jak copyright w WPF c #.

         var  handle = BitmapImage2Bitmap(currentimage).GetHbitmap();



        System.Drawing.Image img = System.Drawing.Image.FromHbitmap(handle);
        System.Drawing.Imaging.PropertyItem prop = img.PropertyItems[0];
        SetProperty(ref prop, 33432, "Copyright");
        img.SetPropertyItem(prop);

        


        img.Save(@"C:\images\test.jpg");

Próbowałem już użyć powyższego kodu, ale mówi, że indeks był poza obszarem tablicy.

Odpowiedzi

Charlieface Dec 30 2020 at 09:52
var prop = img.GetPropertyItem(0x503B);
prop.Value = Encoding.Ascii.GetBytes("copyright name");
prop.Len = prop.Value.Length;
img.SetPropertyItem(prop);

Wartość 0x503B pochodzi stąd: PropertyItem.Id Property