CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Mar 2008
    Posts
    142

    cropping and stretching

    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
    Code:
    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
    kindly help me........thanks
    Attached Files Attached Files

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured