hi all,
i m making a window application in C# and i want crop an image in circle form from picture box with mouse event.
can any one help me ...
thanks in advance.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ritesh SinghPosted Jun 25, 2010, 6:44 AM
For the time being you can follow this link.
http://forums.devx.com/showthread.php?t=160827
Babita shivadePosted Apr 25, 2009, 1:36 AM
ok thanks..
if i m getting answer for this problem then i will tell you.
thanks again.
Manath PathanaPosted Apr 24, 2009, 9:39 PM
But if I have free time, I will search for you.
If you can do or search it, Don't forget tell me.
I want to know too.
OK?
Babita shivadePosted Apr 24, 2009, 4:40 AM
hi...
Thank you very much for helping me....
i want to ask one think this code is crop a image in rectangular form. do you have any idea about circle cropping. in which i can crop a image in circular form and save it as also in circular form .... if you have idea about it plz help me..
thanks again.
Manath PathanaPosted Apr 24, 2009, 2:03 AM
Sorry, I am not sure in C# code.
but you can go to website http://www.developerfusion.com/tools/convert/vb-to-csharp/
for convert from VB.Net code to C# code.
If you still can not do, please reply to me. I will try do it for you.
Good Luck.
Babita shivadePosted Apr 20, 2009, 1:47 AM
hi,
thank you very much...........
but i need this code in C# language can u help me....
thanks again.............
Manath PathanaPosted Apr 20, 2009, 12:45 AM
please write code below.
Imports System.Drawing
Public cropPenSize As Integer = 2
Public cropDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
Public cropPenColor As Color = Color.Aquamarine
Public c As Cursors
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Try
Dim openDLG As New OpenFileDialog
openDLG.Filter = "Image Files (*.bmp, *.gif, *.jpg)|*.bmp;*.gif;*.jpg"
If openDLG.ShowDialog = DialogResult.OK Then
p.Image = Image.FromFile(openDLG.FileName, True)
End If
Catch exc As Exception
MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnCrop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCrop.Click
Try
If cropWidth < 1 Then
MessageBox.Show("You need to first select what portion of the image to crop.", " No cropping Cordinates!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim bit As Bitmap = New Bitmap(p.Image, p.Width, p.Height)
cropBitmap = New Bitmap(cropWidth, cropHeight)
Dim g As Graphics = Graphics.FromImage(cropBitmap)
g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel)
pbCrop.Image = cropBitmap
Catch exc As Exception
MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
If pbCrop.Image Is Nothing Then
MessageBox.Show("You have not edited the original image. There is no new image to save.", " Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim saveDLG As SaveFileDialog = New SaveFileDialog
saveDLG.Filter = "Image Files (*.bmp, *.gif, *.jpg)|*.bmp;*.gif;*.jpg"
If saveDLG.ShowDialog = DialogResult.OK Then
If saveDLG.FileName.EndsWith("bmp") Then
pbCrop.Image.Save(saveDLG.FileName, ImageFormat.Bmp)
ElseIf saveDLG.FileName.EndsWith("gif") Then
pbCrop.Image.Save(saveDLG.FileName, ImageFormat.Gif)
Else
pbCrop.Image.Save(saveDLG.FileName, ImageFormat.Jpeg)
End If
saveDLG.Dispose()
End If
Catch exc As Exception
MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub p_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles p.MouseUp
Try
Cursor = c.Default
Catch exc As Exception
MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub p_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles p.MouseMove
Try
If p.Image Is Nothing Then Exit Sub
If e.Button = MouseButtons.Left Then
p.Refresh()
cropWidth = e.X - cropX
cropHeight = e.Y - cropY
p.CreateGraphics.DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight)
End If
GC.Collect()
Catch exc As Exception
If Err.Number = 5 Then Exit Sub
MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class