Windows update KB4040972/73 causes black images with WPF classes

你说的曾经没有我的故事 提交于 2019-12-05 18:39:07

问题


I have an application relying on Deep zoom images (convertion from a PNG to a pyramid of JPGs in various scale) which we use DeepZoomTools.dll for. This is relying on PresentationCore.dll and has been working fine for years.

After the rollout of KB4040972 and KB4040973, the conversion from PNG to JPG generates (depending on coordinates) black images instead of the image it should contain.

If the below code is run in a console or desktop app, it works.

It ONLY doesn't work if run under high privilege SYSTEM account (e.g. from Task scheduler).

I have created a project to reproduce the issue, code below:

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();
 }
}

Any clues out there?


回答1:


Microsoft has published an article where they state that they are aware of this problem and are working on a resolution. They also provide a workaround, basically to temporary remove the September 12, 2017, Security and Quality Rollup update.

See: https://support.microsoft.com/en-us/help/4043601/rendering-issues-after-the-september-12-2017-net-security-and-quality




回答2:


Discussion continued on 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 Seems to be more than me having this issue.




回答3:


For us in the end the recommended update from Microsoft KB4043767 solved this issue. This will be part of the October rollout (currently in Preview).



来源:https://stackoverflow.com/questions/46283894/windows-update-kb4040972-73-causes-black-images-with-wpf-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!