【发布时间】:2015-11-18 14:42:20
【问题描述】:
我正在尝试将图片框画成圆形,这是我的代码:
Private WithEvents pParent As ThumbControl
Sub New(ByVal pnParent As ThumbControl, ByVal Path As String, Optional ByVal DataString As String = "")
pParent = pnParent
strPath = Path
strData = DataString
Me.SizeMode = Windows.Forms.PictureBoxSizeMode.StretchImage
Me.Size = New Size(100, 100)
Dim gp As New System.Drawing.Drawing2D.GraphicsPath()
gp.AddEllipse(0, 0, Me.Width - 3, Me.Height - 3)
Dim rg As New Region(gp)
Me.Region = rg
End Sub
绘画方法:
Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)
If Not bSelected Then
If pParent.HighLightMode = iHighliteMode.GlassAndForeGround Then
If bOver Then
Dim rc As New Rectangle(0, 0, 100, 100)
Dim rc1 As New Rectangle(0, 0, 100, 50)
pe.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(100, pParent.Highlight.R, pParent.Highlight.G, pParent.Highlight.B)), rc)
Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(rc1, Color.FromArgb(180, 255, 255, 255), Color.FromArgb(80, 255, 255, 255), Drawing2D.SmoothingMode.AntiAlias)
pe.Graphics.FillEllipse(br, rc1)
End If
ElseIf pParent.HighLightMode = iHighliteMode.BackGroundOnly Then
If bOver Then
Dim rc1 As New Rectangle(-2, -2, 100, 100)
Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(rc1, Color.FromArgb(180, 255, 255, 255), Color.FromArgb(80, 255, 255, 255), Drawing2D.SmoothingMode.AntiAlias)
pe.Graphics.FillEllipse(br, rc1)
End If
ElseIf pParent.HighLightMode = iHighliteMode.GlassOnly Then
If bOver Then
Dim rc1 As New Rectangle(0, 0, 100, 100)
Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(rc1, Color.FromArgb(180, 255, 255, 255), Color.FromArgb(80, 255, 255, 255), Drawing2D.SmoothingMode.AntiAlias)
pe.Graphics.FillEllipse(br, rc1)
End If
ElseIf pParent.HighLightMode = iHighliteMode.GlassAndBackGround Then
If bOver Then
Dim rc1 As New Rectangle(0, 0, 100, 100)
Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(rc1, Color.FromArgb(180, 255, 255, 255), Color.FromArgb(80, 255, 255, 255), Drawing2D.SmoothingMode.AntiAlias)
pe.Graphics.FillEllipse(br, rc1)
End If
End If
'Dim irc1 As New Rectangle(0, 0, 90, 100)
'pe.Graphics.DrawEllipse(New Pen(pParent.SelectedColor, 1), irc1)
End If
'If bSelected Then
' Dim irc As New Rectangle(0, 0, 90, 90)
' pe.Graphics.DrawEllipse(New Pen(pParent.SelectedColor, 2), irc)
'End If
End Sub
Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaintBackground(pevent)
If Not bSelected Then
If pParent.HighLightMode = iHighliteMode.GlassAndBackGround Then
If bOver Then
'Dim rc As New Rectangle(0, 0, 180, 150)
'Dim rc1 As New Rectangle(0, 0, 100, 80)
'pevent.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(100, pParent.Highlight.R, pParent.Highlight.G, pParent.Highlight.B)), rc)
'Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(rc1, Color.FromArgb(180, 255, 255, 255), Color.FromArgb(80, 255, 255, 255), Drawing2D.LinearGradientMode.Vertical)
'pevent.Graphics.FillRectangle(br, rc1)
End If
ElseIf pParent.HighLightMode = iHighliteMode.BackGroundOnly Then
If bOver Then
Dim rc As New Rectangle(0, 0, 90, 100)
Dim rc1 As New Rectangle(0, 0, 100, 80)
pevent.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(100, pParent.Highlight.R, pParent.Highlight.G, pParent.Highlight.B)), rc)
Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(rc1, Color.FromArgb(180, 255, 255, 255), Color.FromArgb(80, 255, 255, 255), Drawing2D.SmoothingMode.AntiAlias)
End If
End If
End If
End Sub
我得到一条非平滑曲线,如下所示:
如何获得平滑的圆角曲线
【问题讨论】:
标签: vb.net image graphics antialiasing smooth