C# 带画笔的Oxyplot注释

C# 带画笔的Oxyplot注释,c#,wpf,xaml,oxyplot,C#,Wpf,Xaml,Oxyplot,我想给我的OxyPlot的RectangleAnnotation涂上比普通颜色更漂亮的颜色,即某种类型的画笔(GradientBrush等)。我在WPF工作 他们GitHub站点上的这个问题()表明可以为注释提供渐变,但我找不到建议的示例 有没有办法将画笔应用于矩形批注?或者在图形上创建与轴上的值链接的彩色区域的任何其他方法?我认为这是最简单的方法 我将其修改为矩形注释,因为示例填充了整个背景。希望能有帮助 效果: // create a gradient image of height n i

我想给我的
OxyPlot
RectangleAnnotation
涂上比普通颜色更漂亮的颜色,即某种类型的
画笔(
GradientBrush
等)。我在WPF工作

他们GitHub站点上的这个问题()表明可以为注释提供渐变,但我找不到建议的示例

有没有办法将画笔应用于
矩形批注
?或者在图形上创建与轴上的值链接的彩色区域的任何其他方法?

我认为这是最简单的方法

我将其修改为矩形注释,因为示例填充了整个背景。希望能有帮助

效果:

// create a gradient image of height n
int n = 256;
var imageData1 = new OxyColor[n, 1];
for (int i = 0; i < n; i++)
{
    imageData1[i, 0] = OxyColor.Interpolate(OxyColors.Red, OxyColors.Blue, i / (n - 1.0));
}

PngBitmapEncoder encoder = new PngBitmapEncoder();
PngEncoder encode = new PngEncoder(new PngEncoderOptions());
var image1 = new OxyImage(encode.Encode(imageData1));

ImageAnnotation anotation = new ImageAnnotation
{
    ImageSource = image1,
    Interpolate = true,
    Layer = AnnotationLayer.BelowAxes,
    X = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
    Y = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
    Width = new PlotLength(0.1, PlotLengthUnit.RelativeToPlotArea),
    Height = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
    HorizontalAlignment = HorizontalAlignment.Left,
    VerticalAlignment = VerticalAlignment.Top
};
plotModel.Annotations.Add(anotation);

代码:

// create a gradient image of height n
int n = 256;
var imageData1 = new OxyColor[n, 1];
for (int i = 0; i < n; i++)
{
    imageData1[i, 0] = OxyColor.Interpolate(OxyColors.Red, OxyColors.Blue, i / (n - 1.0));
}

PngBitmapEncoder encoder = new PngBitmapEncoder();
PngEncoder encode = new PngEncoder(new PngEncoderOptions());
var image1 = new OxyImage(encode.Encode(imageData1));

ImageAnnotation anotation = new ImageAnnotation
{
    ImageSource = image1,
    Interpolate = true,
    Layer = AnnotationLayer.BelowAxes,
    X = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
    Y = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
    Width = new PlotLength(0.1, PlotLengthUnit.RelativeToPlotArea),
    Height = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
    HorizontalAlignment = HorizontalAlignment.Left,
    VerticalAlignment = VerticalAlignment.Top
};
plotModel.Annotations.Add(anotation);
//创建高度为n的渐变图像
int n=256;
var imageData1=新的OxyColor[n,1];
对于(int i=0;i
您看过这里吗?