1

I am trying to write metadata to a png file using BitmapEncoder.

stream = co_await storageFile.OpenAsync(WS::FileAccessMode::ReadWrite);
decoder = co_await Windows::Graphics::Imaging::BitmapDecoder::CreateAsync(stream);
encoder = co_await Windows::Graphics::Imaging::BitmapEncoder::CreateForTranscoding(stream, decoder);

auto propertySet = winrt::Windows::Graphics::Imaging::BitmapPropertySet();
auto ratingValue = winrt::box_value(L"10");
auto value = winrt::Windows::Graphics::Imaging::BitmapTypedValue(ratingValue, winrt::Windows::Foundation::PropertyType::String);
propertySet.Insert(L"/tEXt/{str=Rating}", value);

co_await encoder.BitmapProperties().SetPropertiesAsync(propertySet);
co_await encoder.FlushAsync();

Image before: enter image description here

Image after: enter image description here

gunturu mahesh
  • 113
  • 4
  • 9
  • 1
    This code cannot work anyway as you're using the input stream (read) for output in CreateForTranscoding (and BTW, this should be CreateForTranscodingAsync). – Simon Mourier Oct 14 '21 at 05:59

0 Answers0