4
嘗試使用在元數據中設置的軟件名稱保存圖像時,我收到異常「指定的BitmapEncoder不支持全局元數據。」在保存爲C#時在圖像元數據中設置軟件名稱
我該如何做到這一點?
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);
}