Set ImageAnnoation image using embedded Resources instead of a file name

1.2k Views Asked by At

I'm using the Chart control from the DataVisualization library, and want to use image annotations on my chart. The problem is that the ImageAnnotation.Image property is a path to the image, and there doesn't appear to be an exposed Bitmap property that I could use to load the image from the Resources object like I can for any other .net control.

Is there anyway I'm overlooking to load this using embedded resources instead of reading a separate file off the disk?

1

There are 1 best solutions below

3
On BEST ANSWER

I found the answer. You need to add the image to the parent Chart's NamedImage collection.

private string imageName = "myImage";

//in constructor
NamedImage namedImage = new NamedImage(imageName, Properties.Resources.myImage);
mChart.Images.Add(namedImage);

//where creating the annotation
ImageAnnotation imageAnnotation = new ImageAnnotation();
imageAnnotation.Image = imageName;