P.S.
Hier mein Rubberband-Code für das Bild-Beschneiden
Dim editPicEditor As Boolean
Dim hatRubberBand As Boolean
' Rubberband
Dim cropX As Integer
Dim cropY As Integer
Dim cropWidth As Integer
Dim cropHeight As Integer
Dim mousePosX As Integer
Dim mousePosY As Integer
Dim mouseMovePosX As Integer
Dim mouseMovePosY As Integer
Dim oCropX As Integer
Dim oCropY As Integer
Dim cropBitmap As Bitmap
Public cropPen As Pen
Public cropPenSize As Integer = 2
Public cropDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
Public cropPenColor As Color = Color.Red
Private Sub tsc_PicEditor_PictureBox_MouseEnter(sender As Object, e As _
EventArgs) Handles tsc_PicEditor_PictureBox.MouseEnter
If editPicEditor = True Then
tsc_PicEditor.Cursor = Cursors.Cross
End If
End Sub
Private Sub tsc_PicEditor_PictureBox_MouseLeave(sender As Object, e As _
EventArgs) Handles tsc_PicEditor_PictureBox.MouseLeave
tsc_PicEditor.Cursor = Cursors.Default
End Sub
Private Sub tsc_PicEditor_PictureBox_MouseDown(ByVal sender As _
System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
tsc_PicEditor_PictureBox.MouseDown
Try
cropWidth = 0
cropHeight = 0
hatRubberBand = False
If e.Button = Windows.Forms.MouseButtons.Left Then
If editPicEditor = True Then
cropX = e.X
cropY = e.Y
cropPen = New Pen(cropPenColor, cropPenSize)
cropPen.DashStyle = DashStyle.DashDotDot
End If
End If
tsc_PicEditor_PictureBox.Refresh()
Catch exc As Exception
End Try
update_Menu_PicEditor()
End Sub
Private Sub tsc_PicEditor_PictureBox_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
tsc_PicEditor_PictureBox.MouseMove
Try
If tsc_PicEditor_PictureBox.Image Is Nothing Then Exit Sub
mousePosX = e.X
mousePosY = e.Y
If e.Button = Windows.Forms.MouseButtons.Left Then
If editPicEditor = True Then
hatRubberBand = True
tsc_PicEditor_PictureBox.Refresh()
mouseMovePosX = e.X
mouseMovePosY = e.Y
cropWidth = e.X - cropX
cropHeight = e.Y - cropY
tsc_PicEditor_PictureBox.CreateGraphics.DrawRectangle( _
cropPen, cropX, cropY, cropWidth, cropHeight)
End If
End If
update_Statusleiste_PicEditor()
Catch exc As Exception
If Err.Number = 5 Then Exit Sub
End Try
End Sub
Private Sub tsc_PicEditor_PictureBox_MouseUp(sender As Object, e As _
MouseEventArgs) Handles tsc_PicEditor_PictureBox.MouseUp
update_Menu_PicEditor()
End Sub
Private Sub mnu_PicEditor_Bearbeiten_Beschneiden_Click(sender As Object, e _
As EventArgs) Handles mnu_PicEditor_Bearbeiten_Beschneiden.Click
Bild_Beschneiden()
End Sub
Private Sub Bild_Beschneiden()
Try
If cropWidth < 1 Then
Exit Sub
End If
tsc_PicEditor_PictureBox.Visible = False
Dim rect As Rectangle = New Rectangle(cropX, cropY, cropWidth, _
cropHeight)
Dim bit As Bitmap = New Bitmap(tsc_PicEditor_PictureBox.Image, _
tsc_PicEditor_PictureBox.Width, tsc_PicEditor_PictureBox.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)
tsc_PicEditor_PictureBox.Image = cropBitmap
PictureBoxAnpassen()
tsc_PicEditor_PictureBox.Visible = True
Catch exc As Exception
End Try
hatRubberBand = False
PicEditorGeändert = True
update_Menu_PicEditor()
End Sub |