[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
Re: How to make an elliptical bitmap?
You mean copy to the clipboard?
I'm not sure how you would do that...
Re: How to make an elliptical bitmap?
You can use Color.Transparent for pixels outside of the ellipse
Re: How to make an elliptical bitmap?
Quote:
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
gp.AddEllipse(rect)
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
Re: How to make an elliptical bitmap?
Thank you boops! That was exactly what I was looking for.