使用 visual studios 2022 C# for revit 将图像添加到按钮的问题

issue adding images to buttons using visual studios 2022 C# for revit

我 运行 遇到了一个问题,在我尝试输入图像之前一切正常。我正在尝试将它们作为资源从内部引入,而不是不确定在这里做什么是 C# 的新手。下面是向我抛出错误的代码。以及错误消息。
error message

#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.CSharp;
using System.Media;
using System.Reflection;
using System.Drawing.Imaging;
using System.IO.Packaging;
using System.Drawing; 
#endregion

namespace TpMechanical
{
    internal class App : IExternalApplication
    {
        public Result OnStartup(UIControlledApplication a)
        {
            String tabname = "TpMechanical";
            String panelname = "Tools";
          
            Bitmap button1Image = (System.Drawing.Bitmap)TpMechanical.Properties.Resources.ResourceManager.GetObject("Untitled design.png");
            Bitmap button2Image = (System.Drawing.Bitmap)TpMechanical.Properties.Resources.ResourceManager.GetObject("Untitled design2.png");
            Bitmap button3Image = (System.Drawing.Bitmap)TpMechanical.Properties.Resources.ResourceManager.GetObject("Untitled design3.png");


            a.CreateRibbonTab(tabname);
            var Tools = a.CreateRibbonPanel(tabname, panelname);
            var button1 = new PushButtonData("TpButton1", "Button1", Assembly.GetExecutingAssembly().Location, "TpMechanical.command");
            button1.ToolTip = " This is a short description";
            button1.LongDescription = "This is a long description \n " +
                "this is the second line";
            var btn1 = Tools.AddItem(button1);

            var button2 = new PushButtonData("TpButton2", "Button2", Assembly.GetExecutingAssembly().Location, "TpMechanical.command2");
            button2.ToolTip = " This is a short description";
            button2.LongDescription = "This is a long description \n " +
                "this is the second line";
   
            var button3 = new PushButtonData("TpButton3", "Button3", Assembly.GetExecutingAssembly().Location, "TpMechanical.command3");
            button3.ToolTip = " This is a short description";
            button3.LongDescription = "This is a long description \n " +
                "this is the second line";
            
            Tools.AddStackedItems(button2, button3);
            

            return Result.Succeeded;
        }

        public Result OnShutdown(UIControlledApplication a)
        {
            return Result.Succeeded;
        }
    }
}

使用 c# 中的标准位图库从资源导入图像

Bitmap b1Image = (System.Drawing.Bitmap)(WindowsFormsApp1.Properties.Resources.ResourceManager.GetObject("Name of the image"));

您需要用正确的命名空间替换“WindowsFormsApp1”。

在使用 System.Windows.Media.Imaging 时,您需要:

BitmapImage b1Image = (System.Windows.Media.Imaging.BitmapImage)(WindowsFormsApp1.Properties.Resources.ResourceManager.GetObject("Name of the image"));