Convert ImageSource to BitmapImage - WPF

时光怂恿深爱的人放手 提交于 2019-12-04 00:29:06

问题


I'm using a class library that generates a large ImageSource, > 3000x3750 pixels. I would like to convert this ImageSource to BitmapImage so that I can take advantage of DecodePixelWidth or DecodePixelHeight instead of resizing it everytime this image is generated.

I need to display this image for the user first, and most of the users have a screen resolution of 1024x768, I'm binding this ImageSource to an Image control for this, but it can be noticed how "heavy" it is.

How can I do this? Or what is the best solution for this case?

thanks!


回答1:


I know it's a old post, but try doing:

myBitmapImage = myImageSource as BitmapImage;

That works well.




回答2:


The BitmapImage type inherits BitmapSource and ultimately ImageSource (both of which are abstract classes). You need to check what the actual type of your object is, i.e. check object.GetType().Name. If you're in luck, it may actually be returning a BitmapSource object and you will simply need to cast it to that type before being able to use it as such.



来源:https://stackoverflow.com/questions/920517/convert-imagesource-to-bitmapimage-wpf

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