我试图通过在每个角上使用2张图像来绘制标题,然后重复另一张图像以填充两者之间的区域。这是未升级时的样子(正确):
但是当我尝试放大图像时,底部和右侧会变得透明。我在相同的坐标上绘制了一些彩色矩形,以表明它们是正确的:
当我关闭插值时,间隙变得完全透明:
我不知道为什么会这样,特别是因为它在绘制矩形时效果很好。
源代码:
protected override void OnPaint(PaintEventArgs a_EventArgs)
{
var gfx = a_EventArgs.Graphics;
var left_size = new Rectangle();
var right_size = new Rectangle();
var middle_size = new Rectangle();
left_size.Height = Height;
left_size.Width = Math.Max(1, (int)Math.Floor((left_size.Height / ((double)HeaderLeftBitmap.Height)) * Resources.ItemsHeaderWhiteLeft.Width));
left_size.X = 0;
left_size.Y = 0;
right_size.Height = Height;
right_size.Width = Math.Max(1, (int)Math.Floor((right_size.Height / ((double)HeaderRightBitmap.Height)) * Resources.ItemsHeaderWhiteRight.Width));
right_size.X = Width - left_size.Width;
right_size.Y = 0;
middle_size.Height = Height;
middle_size.Width = Math.Max(1, (int)Math.Floor((middle_size.Height / ((double)HeaderMiddleBitmap.Height)) * Resources.ItemsHeaderWhiteMiddle.Width));
middle_size.X = left_size.Width;
middle_size.Y = 0;
//gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
//gfx.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
bool toggle = false;
for (; middle_size.X < right_size.X; middle_size.X += middle_size.Width)
{
gfx.FillRectangle(toggle ? Brushes.Red : Brushes.LightGreen, middle_size);
toggle = !toggle;
gfx.DrawImage(HeaderMiddleBitmap, middle_size);
}
gfx.FillRectangle(Brushes.Blue, left_size);
gfx.FillRectangle(Brushes.Blue, right_size);
gfx.DrawImage(HeaderLeftBitmap, left_size);
gfx.DrawImage(HeaderRightBitmap, right_size);
}
图像(通过资源文件加载):