xarial / xcad

Framework for developing CAD applications for SOLIDWORKS, including add-ins, stand-alone applications, macro features, property manager pages, etc.
https://xcad.net
MIT License
129 stars 27 forks source link

Exception when using indexed pixel format for icons #19

Open artem1t opened 3 years ago

artem1t commented 3 years ago

The following exception is thrown System.Exception: 'A Graphics object cannot be created from an image that has an indexed pixel format.' if using indexed pixel format image (256 color BMP) as an icon

256bitmap.zip

[ComVisible(true)]
    public class BitmapButtonsAddIn : Xarial.XCad.SolidWorks.SwAddInEx
    {
        [ComVisible(true)]
        public class PMPModel : SwPropertyManagerPageHandler 
        {
            [BitmapButton(typeof(Resources), nameof(Resources._256bitmap), 64, 64)]
            public Action Button1 { get; set; } = () => { };
        }

        private SwPropertyManagerPage<PMPModel> m_Page;

        public override void OnConnect()
        {
            m_Page = CreatePage<PMPModel>();
        }
    }