Color.White 绘制 GraphicsPath 时不可见
Color.White not visible when drawing GraphicsPath
当我使用 Color.White 以外的任何其他颜色时,以下代码工作正常:
Public Sub PaintVignette(ByVal b As Bitmap, ByVal uColor As Color, ByVal bounds As Rectangle)
Dim d As Double = 0.70712
Using g As Graphics = Graphics.FromImage(b)
Dim ellipsebounds As Rectangle = bounds
ellipsebounds.Offset(-ellipsebounds.X, -ellipsebounds.Y)
Dim x As Integer = ellipsebounds.Width - CInt(Math.Round(d * ellipsebounds.Width))
Dim y As Integer = ellipsebounds.Height - CInt(Math.Round(d * ellipsebounds.Height))
ellipsebounds.Inflate(x, y)
Using path As GraphicsPath = New GraphicsPath()
path.AddEllipse(ellipsebounds)
Using brush As PathGradientBrush = New PathGradientBrush(path)
brush.WrapMode = WrapMode.Tile
brush.CenterColor = Color.FromArgb(0, 0, 0, 0)
brush.SurroundColors = New Color() {Color.FromArgb(255, uColor.R, uColor.G, uColor.B)}
Dim blend As Blend = New Blend()
blend.Positions = New Single() {0F, 0.2F, 0.4F, 0.6F, 0.8F, 1.0F}
blend.Factors = New Single() {0F, 0.5F, 1.0F, 1.0F, 1.0F, 1.0F}
brush.Blend = blend
Dim oldClip As Region = g.Clip
g.Clip = New Region(bounds)
g.FillRectangle(brush, ellipsebounds)
g.Clip = oldClip
End Using
End Using
End Using
End Sub
将 Color.Green 作为颜色参数传递会产生这样的图像:
传递 Color.White 结果是这样的图像:
正如你所看到的,白色根本没有画出来。
有人看到这里发生了什么吗?
如果您检查屏幕截图中的各个像素(主要是网格的像素),您会发现即使您使用 Color.White
,实际上也绘制了晕影,尽管它几乎不可见:
很难注意到它,因为你有白色背景,而且小插图相当透明。为了能够更清楚地看到它,您需要降低晕影的透明度(或增加强度,以正确的术语为准)。
请注意,由于小插图和背景都是白色的,绘制它只会影响非白色像素(即网格)。如果你想让它更像一个阴影,你必须将颜色更改为灰色的一些变化。
当我使用 Color.White 以外的任何其他颜色时,以下代码工作正常:
Public Sub PaintVignette(ByVal b As Bitmap, ByVal uColor As Color, ByVal bounds As Rectangle)
Dim d As Double = 0.70712
Using g As Graphics = Graphics.FromImage(b)
Dim ellipsebounds As Rectangle = bounds
ellipsebounds.Offset(-ellipsebounds.X, -ellipsebounds.Y)
Dim x As Integer = ellipsebounds.Width - CInt(Math.Round(d * ellipsebounds.Width))
Dim y As Integer = ellipsebounds.Height - CInt(Math.Round(d * ellipsebounds.Height))
ellipsebounds.Inflate(x, y)
Using path As GraphicsPath = New GraphicsPath()
path.AddEllipse(ellipsebounds)
Using brush As PathGradientBrush = New PathGradientBrush(path)
brush.WrapMode = WrapMode.Tile
brush.CenterColor = Color.FromArgb(0, 0, 0, 0)
brush.SurroundColors = New Color() {Color.FromArgb(255, uColor.R, uColor.G, uColor.B)}
Dim blend As Blend = New Blend()
blend.Positions = New Single() {0F, 0.2F, 0.4F, 0.6F, 0.8F, 1.0F}
blend.Factors = New Single() {0F, 0.5F, 1.0F, 1.0F, 1.0F, 1.0F}
brush.Blend = blend
Dim oldClip As Region = g.Clip
g.Clip = New Region(bounds)
g.FillRectangle(brush, ellipsebounds)
g.Clip = oldClip
End Using
End Using
End Using
End Sub
将 Color.Green 作为颜色参数传递会产生这样的图像:
传递 Color.White 结果是这样的图像:
正如你所看到的,白色根本没有画出来。
有人看到这里发生了什么吗?
如果您检查屏幕截图中的各个像素(主要是网格的像素),您会发现即使您使用 Color.White
,实际上也绘制了晕影,尽管它几乎不可见:
很难注意到它,因为你有白色背景,而且小插图相当透明。为了能够更清楚地看到它,您需要降低晕影的透明度(或增加强度,以正确的术语为准)。
请注意,由于小插图和背景都是白色的,绘制它只会影响非白色像素(即网格)。如果你想让它更像一个阴影,你必须将颜色更改为灰色的一些变化。