我有一个应用程序依赖于Deep Zoom图像(将PNG转换为不同比例的JPG金字塔),我们使用DeepZoomTools.dll来实现。这依赖于PresentationCore.dll,多年来一直运行良好。
在KB4040972和KB4040973发布之后,从PNG转换为JPG时会生成黑色图像(根据坐标而定),而不是应该包含的图像。
如果在控制台或桌面应用程序中运行下面的代码,则可以正常工作。
仅当在高特权SYSTEM帐户下运行(例如从任务计划程序)时才无法工作。
我创建了一个项目来重现此问题,以下是代码:
在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();
}
}
有线索吗?