如何并排绘制两个不重叠的矩形?

时间:2018-07-29 20:00:23

标签: c# direct2d drawrectangle

我正在使用以下代码绘制一系列矩形:

        for (int j = 0; j < list.Count - 1; j++)//
        {
            var item = list[j];

            var nextitem = list[j + 1];

            double y;
            y = yScale.Transform(item.Y, ChartScaleType.Logarythmic);

            var y1 = yScale.Transform(nextitem.Y, ChartScaleType.Logarythmic);

            var perc = item.Color / div;                

            var transparency = (float) (perc * contrast);

            var c = 255F;
            if (dayColors)
            {
                c = 0;
            }

            var db = Math.Abs(item.Disbalance);
            var ageTransform = 1;
            var split =  Math.Min(1, (float) (db/(db + 1)* ageTransform * polarity));

            using (var brush = this.RenderTarget.CreateSolidColorBrush(new D2D.ColorF(c,c, c, transparency*(1-split))))
            {
                var rectangle = new D2D.RectF((float)Math.Min(x, x1), (float)Math.Max(y, y1), (float)Math.Max(x, x1), (float)Math.Min(y, y1));
                this.RenderTarget.FillRectangle(rectangle, brush);
            }

            var disbalanceColor = increasedDisbalanceColor;
            if (item.Disbalance<0)
            {
                disbalanceColor = decreasedDisbalanceColor;
            }


            using (var brush = this.RenderTarget.CreateSolidColorBrush(new D2D.ColorF(disbalanceColor.R/255F, disbalanceColor.G/255F, disbalanceColor.B/255F, transparency * ( split))))
            {
                var rectangle = new D2D.RectF((float)Math.Min(x, x1), (float)Math.Max(y, y1), (float)Math.Max(x, x1), (float)Math.Min(y, y1));
                this.RenderTarget.FillRectangle(rectangle, brush);
            }
        }

这导致矩形之间用灰线分开(请忽略灰点):

grey lines around rectangles

我希望图像尽可能平滑,并且我不想灰线。

除掉这些的好方法是什么?

0 个答案:

没有答案