1

我有这个功能来检查 PNG 颜色深度:

MemoryStream stream = new MemoryStream(File.ReadAllBytes(path));
var source = BitmapFrame.Create(stream, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnDemand);
return source.Format.BitsPerPixel;

每当此代码运行时,应用程序的 DPI 缩放将中断并重置为 100%,并且窗口不再最大化。

我已经设法隔离了导致这种情况的代码行,它是 BitmapFrame.Create()。

如果我完全跳过代码,甚至会发生这种情况,如下所示:

return 32;
MemoryStream stream = new MemoryStream(File.ReadAllBytes(path));
var source = BitmapFrame.Create(stream, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnDemand);
return source.Format.BitsPerPixel;

“return 32”之后的其他行都不会运行,但是如果我运行该函数,该错误仍然会被触发。只有当我真正注释掉这些行时它才有效。

有任何想法吗?我根本不明白这是怎么可能的,这使得调试变得困难。

4

0 回答 0