Link to home
Start Free TrialLog in
Avatar of PLavelle
PLavelle

asked on

GDI DrawEllipse on Bitmap - Ellipse cut off

The sides of the ellipse are getting cut off when I draw it to this image. Any ideas?

        Dim oGraphics As Graphics = Nothing
        Dim oFillBrush As SolidBrush = Nothing
        Dim oBorderPen As Pen = Nothing
       imgShape.Left = 0
       imgShape.Top = 0
       imgShape.Width = Me.Width
       imgShape.Height = Me.Height
       imgShape.Image = New Bitmap(imgShape.Width, imgShape.Height)
       oGraphics = Graphics.FromImage(imgShape.Image)
       oGraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
       oFillBrush = New SolidBrush(Me.BackColor)
       oBorderPen = New Pen(Me.LineColor, Me.LineWidth)
       Dim iOffset As Int32 = 0
       Dim oImageRect As New Rectangle(imgShape.ClientRectangle.X + iOffset, imgShape.ClientRectangle.X + iOffset, imgShape.ClientRectangle.Width - iOffset * 2, imgShape.ClientRectangle.Height - iOffset * 2)
       oGraphics.FillEllipse(oFillBrush, oImageRect)
       oGraphics.DrawEllipse(oBorderPen, oImageRect)
       'Dispose of everything
ASKER CERTIFIED SOLUTION
Avatar of Kinger247
Kinger247

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mohamed Zedan
in this line

   Dim oImageRect As New Rectangle(imgShape.ClientRectangle.X + iOffset, imgShape.ClientRectangle.X + iOffset, imgShape.ClientRectangle.Width - iOffset * 2, imgShape.ClientRectangle.Height - iOffset * 2)

maybe because you used imgshape.ClientRectangle.X in the top Parameter ?
                                                                                                                                                    |
                                                                                                                                            Here V
   Dim oImageRect As New Rectangle(imgShape.ClientRectangle.X + iOffset, imgShape.ClientRectangle.X + iOffset, imgShape.ClientRectangle.Width - iOffset * 2, imgShape.ClientRectangle.Height - iOffset * 2)

but anyways the clientRectangle property always returns a rectangle with x,y = 0,0
so  to make your code right use it this way

   Dim oImageRect As New Rectangle(iOffset, iOffset, imgShape.ClientRectangle.Width - (iOffset * 2), imgShape.ClientRectangle.Height - (iOffset * 2))
Avatar of Kinger247
Kinger247

Hi, did this work for you ?
Avatar of PLavelle

ASKER

Here's what worked:

Dim rcControl As New Rectangle(iLineWidth / 2, iLineWidth / 2, Me.Width - iLineWidth, Me.Height - iLineWidth)

Thanks for the help.