Solved

GDI DrawEllipse on Bitmap - Ellipse cut off

Posted on 2006-11-03
4
536 Views
Last Modified: 2006-11-30
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
0
Comment
Question by:PLavelle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 17870294
You can only offset the height and width values.


    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        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 - 8
        imgShape.Height = Me.Height - 27

        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(Color.Magenta, 2)

        Dim oImageRect As New Rectangle(0, 0, imgShape.Width - 1, imgShape.Height - 1)

        oGraphics.FillEllipse(oFillBrush, oImageRect)
        oGraphics.DrawEllipse(oBorderPen, oImageRect)
        'Dispose of everything
    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Invalidate()
    End Sub
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17872872
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))
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17921947
Hi, did this work for you ?
0
 

Author Comment

by:PLavelle
ID: 18045013
Here's what worked:

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

Thanks for the help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question