i want to crop the picture but when i draw a rectangle on the picture and releases the mouse,picture is croped but picture is stretched
and picture quality becomes bad.
i m worry due this problem...i can't understand it
i m using a picture box and a panel
i m attaching the code along database files...bcoz picture are stored in database
kindly help me........thanksCode:Private Sub pb_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb.MouseDown Try If e.Button = Windows.Forms.MouseButtons.Left Then cropX = e.X cropY = e.Y cropPen = New Pen(cropPenColor, cropPenSize) cropPen.DashStyle = Drawing2D.DashStyle.DashDotDot Cursor = Cursors.Cross End If pb.Refresh() Catch ex As Exception End Try End Sub Private Sub pb_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb.MouseMove Try If pb.Image Is Nothing Then Exit Sub If e.Button = Windows.Forms.MouseButtons.Left Then pb.Refresh() cropWidth = e.X - cropX cropHeight = e.Y - cropY pb.CreateGraphics.DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight) End If Catch ex As Exception End Try End Sub Private Sub pb_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb.MouseUp Try Cursor = Cursors.Default Try If cropWidth < 1 Then Exit Sub End If Dim rect As Rectangle = New Rectangle(cropX, cropY, cropWidth, cropHeight) Dim bit As Bitmap = New Bitmap(pb.Image, pb.Width, pb.Height) cropBitmap = New Bitmap(cropWidth, cropHeight) Dim g As Graphics = Graphics.FromImage(cropBitmap) g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel) pb.Image = cropBitmap Catch ex As Exception End Try Catch ex As Exception End Try End Sub




Reply With Quote