PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 [RESOLVED] How to make an elliptical bitmap?-VBForums

# Thread: [RESOLVED] How to make an elliptical bitmap?

1. ## [RESOLVED] How to make an elliptical bitmap?

Hi!
How can I "crop" out an elliptical portion of a bitmap? The code I posted here only draws the bitmap and the circle. I want to make something that will copy only what is within the circle. (Do I need to use the circle formula for this?)
Thanks. ~NinjaNic

vb Code:
`Public Class Form1     Dim BitmapLocation As New Point(0, 0)    Dim B As New Bitmap(My.Resources.picture)     Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint        e.Graphics.DrawImage(B, New Point(0, 0))        e.Graphics.DrawEllipse(Pens.Black, CreateRectangle)        'I need the part of the bitmap inside the circle.    End Sub     Private Function CreateRectangle() As Rectangle        Dim R As New Rectangle        R.Location = BitmapLocation        If B.Width > B.Height Then            R.Width = B.Height            R.Height = B.Height            R.X += CInt((B.Width - B.Height) / 2)        Else            R.Width = B.Width            R.Height = B.Width            R.Y += CInt((B.Height - B.Width) / 2)        End If        Return R    End Function End Class`

2. ## Re: How to make an elliptical bitmap?

You mean copy to the clipboard?
I'm not sure how you would do that...

3. ## Re: How to make an elliptical bitmap?

You can use Color.Transparent for pixels outside of the ellipse

4. ## Re: How to make an elliptical bitmap?

Originally Posted by NinjaNic
Hi!
How can I "crop" out an elliptical portion of a bitmap? The code I posted here only draws the bitmap and the circle. I want to make something that will copy only what is within the circle. (Do I need to use the circle formula for this?)
Thanks. ~NinjaNic
Here's how:
Code:
```Public Class Form1

Dim BitmapLocation As New Point(0, 0)
Dim B As New Bitmap(My.Resources.picture)

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim rect as Rectangle = CreateRectangle
Dim gp As New Drawing2D.GraphicsPath
e.Graphics.SetClip(gp)
e.Graphics.DrawImage(B, New Point(0, 0))
e.Graphics.ResetClip
e.Graphics.DrawEllipse(Pens.Black, rect)
End Sub

Private Function CreateRectangle() As Rectangle
Dim R As New Rectangle
R.Location = BitmapLocation
If B.Width > B.Height Then
R.Width = B.Height
R.Height = B.Height
R.X += CInt((B.Width - B.Height) / 2)
Else
R.Width = B.Width
R.Height = B.Width
R.Y += CInt((B.Height - B.Width) / 2)
End If
Return R
End Function

End Class```
BB

5. ## Re: How to make an elliptical bitmap?

Thank you boops! That was exactly what I was looking for.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured