谁能告诉我如何解决这个问题?
我有以下代码来保存大尺寸图像 - 我得到一个例外:
private void SaveImage(BitmapSource source, string OutPutPath)
{
source.Freeze();
encoder = new JpegBitmapEncoder();
encoder.QualityLevel = 100;
encoder.Frames.Add(BitmapFrame.Create(source));
Stream fileStream = File.Create(OutPutPath);
try
{
encoder.Save(fileStream);
}
catch (Exception ex)
{
throw ex;
}
finally
{
fileStream.Close();
encoder = null;
}
}
例外是:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
调用堆栈显示:
MS.Win32.PresentationCore.UnsafeNativeMethods.WICBitmapFrameEncode.WriteSource(SafeMILHandle THIS_PTR, SafeMILHandle pIBitmapSource, Int32Rect& r)
System.Windows.Media.Imaging.BitmapEncoder.SaveFrame(SafeMILHandle frameEncodeHandle, SafeMILHandle encoderOptions, BitmapFrame frame)
System.Windows.Media.Imaging.BitmapEncoder.Save(Stream stream)