尝试使用元数据中设置的软件名称保存图像时,出现异常“指定的 BitmapEncoder 不支持全局元数据。”
我怎样才能做到这一点?
using (Stream stream = File.Create(@"D:\Yourfile.png"))
{
RenderTargetBitmap rtb = new RenderTargetBitmap(600, 400, 300, 300, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
//draw on drawing visual
rtb.Render(dv);
BitmapEncoder encoder = null;
BitmapMetadata metadata = null;
encoder = new JpegBitmapEncoder();
((JpegBitmapEncoder)encoder).QualityLevel = 90;
metadata = new BitmapMetadata("jpg");
metadata.ApplicationName = "My Software Name";
encoder.Metadata = metadata;
BitmapFrame bitmapFrame = BitmapFrame.Create(rtb);
encoder.Frames.Add(bitmapFrame);
encoder.Save(stream);
}