简体   繁体   中英

Set ImageAnnoation image using embedded Resources instead of a file name

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM