I am trying to create (encode) a Bitmap into a file - the format shall be JpegXR and I want metadata to be associated with it. WIC and it's counterparts in C# (.Net) do a great job but I fail to creating any kind of metadata object.
This is what I'm trying to do (wb is my image; w/o metadata it works):
WmpBitmapEncoder enc = new WmpBitmapEncoder
{
UseCodecOptions = true,
FrequencyOrder = true, // (progressive)
QualityLevel = 1, // 1=lossless 255=worst
HorizontalTileSlices = 0,
VerticalTileSlices = 0,
Lossless = true,
};
var bitmapFrame = BitmapFrame.Create(wb);
var meta0 = bitmapFrame.CreateInPlaceBitmapMetadataWriter();
var meta1 = bitmapFrame.Metadata;
enc.Frames.Add(bitmapFrame);
BitmapMetadata meta2 = new BitmapMetadata("wdp");
enc.Metadata = meta2;
using (var fileStream = new FileStream(target, FileMode.Create))
{
enc.Save(fileStream);
}
The result is: meta0
== null
, meta1
also yields null
and the call to new BitmapMetadata("")
throws an exception regardless of the string I provide: ArgumentException
"Property cannot be found".
So how is one supposed to supply / create image metadata for images created from scratch?