gunturu mahesh
gunturu mahesh

Reputation: 113

BitmapEncoder.CreateForTranscoding corrupts the png image

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

Upvotes: 1

Views: 109

Answers (0)

Related Questions