【问题标题】:c# winforms usercontrol - cannot create System.Drawing.Imagec# winforms usercontrol - 无法创建 System.Drawing.Image
【发布时间】:2012-06-09 01:52:25
【问题描述】:

我正在尝试在内存中创建一个图像,以便我可以组合两个或多个透明图像并将它们作为位图呈现在用户控件的图片框中。

我的开箱密码:

System.Drawing.Image Beat = new System.Drawing.Image()

导致 "无法创建抽象类或接口 'System.Drawing.Image' 的实例"

谁能告诉我为什么?

我正在使用以下指令(以排除歧义)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

非常感谢

【问题讨论】:

    标签: c# winforms image


    【解决方案1】:

    System.Drawing.Image 是抽象的,正如编译器告诉你的那样。您需要选择 Image 的“具体”实现,例如 Bitmap

    【讨论】:

    • 谢谢和抱歉,引用了发布在本网站上的代码stackoverflow.com/questions/2479133/… ... 仔细检查,这是一个 WPF 示例,所以我可以假设它对于 winforms 有所不同?
    • WPF 不使用 System.Drawing.dll,它在 WPF 中是 BitmapSource(我相信,我不是 WPF 专家)。 WinForms 使用 System.Drawing.dll 可以找到Bitmap
    • 好的,我将假设我在上面发布的链接仅适用于 WPF,并且在 WPF 中您可以按照描述的方式创建图像,但在 WinForms 中我必须使用位图。所有这一切都是为了让真实的图像层和透明度发挥作用! ;-) 感谢您的帮助 D
    【解决方案2】:

    System.Drawing.Image 是一个抽象类,这意味着它不能被实例化。您需要创建一个派生自它的具体类的实例,例如 System.Drawing.BitmapSystem.Drawing.Imaging.Metafile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-22
      • 2019-04-02
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 2010-12-07
      • 1970-01-01
      • 2022-01-24
      相关资源
      最近更新 更多