Windows 更新 KB4040972/73 导致 WPF 类产生黑色图片

9
我有一个应用程序依赖于Deep Zoom图像(将PNG转换为不同比例的JPG金字塔),我们使用DeepZoomTools.dll来实现。这依赖于PresentationCore.dll,多年来一直运行良好。
在KB4040972和KB4040973发布之后,从PNG转换为JPG时会生成黑色图像(根据坐标而定),而不是应该包含的图像。
如果在控制台或桌面应用程序中运行下面的代码,则可以正常工作。
仅当在高特权SYSTEM帐户下运行(例如从任务计划程序)时才无法工作。
我创建了一个项目来重现此问题,以下是代码:
public static void TestConvert2(string strFileName, string strOutFileName) {
 JpegBitmapEncoder jpegBitmapEncoder = new JpegBitmapEncoder();
 jpegBitmapEncoder.QualityLevel = 1 + (int) Math.Round(0.95 * 99.0);
 BitmapEncoder encoder = jpegBitmapEncoder;

 Int32Rect inputRect = new Int32Rect(0, 0, 255, 255);
 Rect outputRect = new Rect(0, 0, 255, 255);
 Uri bitmapUri = new Uri(strFileName, UriKind.RelativeOrAbsolute);
 BitmapDecoder bitmapDecoder = BitmapDecoder.Create(bitmapUri,
  BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
 bitmapDecoder = BitmapDecoder.Create(bitmapUri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);

 BitmapSource inputFrame = (BitmapSource) bitmapDecoder.Frames[0];
 BitmapSource source1 = (BitmapSource) new CroppedBitmap(inputFrame, inputRect);
 DrawingVisual drawingVisual = new DrawingVisual();
 using(DrawingContext drawingContext = drawingVisual.RenderOpen()) {
  drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)), null, outputRect);
  drawingContext.DrawImage((ImageSource) source1, outputRect);
  drawingContext.Close();
 }
 RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(255, 255, 96.0, 96.0, PixelFormats.Default);
 renderTargetBitmap.Render((Visual) drawingVisual);
 source1 = (BitmapSource) new FormatConvertedBitmap((BitmapSource) renderTargetBitmap, PixelFormats.Bgr24, (BitmapPalette) null, 0.0);
 BitmapFrame frameToCache = BitmapFrame.Create(source1, (BitmapSource) null, null, (ReadOnlyCollection < ColorContext > ) null);
 encoder.Frames.Add(frameToCache);
 using(FileStream fileStream = new FileStream(strOutFileName, FileMode.Create)) {
  encoder.Save((Stream) fileStream);
  fileStream.Flush();
 }
}

有线索吗?


这可能不是一个适合在SO上提问的好问题,它只是Windows中的一个bug。 - zowers
请参见以下链接:https://social.msdn.microsoft.com/Forums/vstudio/en-US/0f14f14c-5cd3-4505-9168-2ef9dc1f7031/kb-4041083-kb-4040973-has-broken-wpf-rendering-in-services?forum=wpf。这是关于KB 4041083和KB 4040973在服务中破坏WPF渲染的讨论。 - zowers
这里也有同样的问题。 - Carl R
2
微软已确认了这个 bug,卸载 KB 是唯一的选择。他们还友好地建议不要在服务应用程序中使用 WPF 类! - Johan
我们在从WPF保存到位图时遇到了相同的“黑色图像”问题。 - Colonel Panic
3个回答

3

该解决方案可在“.NET Framework 2017年10月安全和质量累积更新”中获得。请参见:https://blogs.msdn.microsoft.com/dotnet/2017/10/10/net-framework-october-2017-security-and-quality-rollup/ - Saso Fleiser


0

对于我们来说,微软推荐的更新KB4043767最终解决了这个问题。这将成为十月份的发布的一部分(目前处于预览阶段)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接