自定义图像从嵌入资源返回null

问题描述 投票:-1回答:1

我正在尝试从我的解决方案中加载一个图像,这个图像是作为jpg嵌入的,但是它表示它没有找到。我正在宣布这两个图像

Image selectedImage = null;
Image emptyImage = null;
selectedImage = Image.FromStream(System.Reflection.Assembly.
GetExecutingAssembly().GetManifestResourceStream(@"selected.png"));

emptyImage = Image.FromStream(System.Reflection.Assembly
.GetExecutingAssembly().GetManifestResourceStream(@"empty.png"));

我需要自定义绘制一个复选框,以便保留样式您可以看到图像包含在我的解决方案中

enter image description here

并且它们都被选为嵌入式资源qazxsw poi

enter image description here

然后我使用此自定义函数将复选框图像绘制到约会上

enter image description here

任何理由为什么我的图像可能为null我认为你不必提供完整的路径,除非它在磁盘上?

编辑2

我尝试了一个资源文件但由于某种原因它也说空了

private void dxsourceNetAppointments_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e)
        {
            VerticalAppointmentViewInfo apptViewInfo = e.ObjectInfo as VerticalAppointmentViewInfo;
            if (apptViewInfo != null)
            {
                Rectangle imageBounds = GetImageBoundsFromViewInfo(apptViewInfo);
                e.DrawDefault();
                bool isCustomSelected = (bool)apptViewInfo.Appointment.CustomFields["CheckedIn"];
                e.Graphics.DrawImage(isCustomSelected ? selectedImage : emptyImage, imageBounds);
                e.Handled = true;
            }
        }
  }
c# winforms
1个回答
0
投票

在调用 selectedImage = WindowsFormsApplication1.SchedurlesImages.selected; emptyImage = WindowsFormsApplication1.SchedurlesImages.empty; 时,您需要使用程序集名称对其进行限定,例如:

GetManifestResourceStream

我建议使用基于RESX的资源文件,而不是使用嵌入式资源?它将代码生成一个包装器,您可以直接使用静态属性。

© www.soinside.com 2019 - 2024. All rights reserved.