为什么可能? :
BitmapSource i = Imaging.CreateBitmapSourceFromHBitmap(...);
我正在写一些应用程序,我发现这一行并且很困惑,因为 MSDN 说 BitmapSource 是抽象类。
最佳答案
BitmapSource
是一个抽象类,因此不能直接创建,但是 Imaging.CreateBitmapSourceFromHBitmap
返回一些具体类,从 BitmapSource
继承,因此可以“转换”为 BitmapSource
。
这类似于拥有一个抽象的 Animal
类,但是有一个继承自它的具体的 Giraffe
类:
Animal a = new Animal(); // illegal
Animal a = Zoo.CreateAnimalFromName("Giraffe"); // valid - returns a Giraffe instance
关于c# - 创建抽象类的对象。怎么可能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23206449/