BitmapImage from file PixelFormat is always bgr32

妖精的绣舞 提交于 2019-12-02 02:27:41

From the Remarks section in BitmapCreateOptions:

If PreservePixelFormat is not selected, the PixelFormat of the image is chosen by the system depending on what the system determines will yield the best performance. Enabling this option preserves the file format but may result in lesser performance.

Therefore you also need to set the PreservePixelFormat flag:

var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(imagePath);
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache
                     | BitmapCreateOptions.PreservePixelFormat;
bitmap.EndInit();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!