Hallo,
Ich habe ein Problem mit Bild Skalierung. Ich möchte mit einem Rubberband ein Stück von PictureBox1 in PictureBox4 vergrößert anzeigen.
Bitte entschuldige mein Deutsch, ich bin Däne.
Wenn ich mit meinem Rubberband auf PictureBox1 eine rectangle zeichne und auf Button1 drücke zeigt PictureBox4 das Bild von der rectangle an. Dass Verhältnis des Bildes stimmt aber nicht.
Ich möchte auch bestimmen wie viel die Vergrößerung sein soll (2x, 3x usw.)
Hat jemand eine Lösung für meine 2 Probleme?
Danke im Voraus.
Mit freundlichen Grüße,
Henrik
Public Class Form1
' Rubberband
Private startCorner As System.Drawing.Point
Private rubberBand As Rectangle
Private rubberBanding As Boolean = False
Private rubberBandColor As Color = Color.Yellow
Dim MyRect1 As New Rectangle
Private Sub PictureBox1_MouseDown(sender As Object, e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
rubberBanding = True
startCorner = e.Location
rubberBand = Rectangle.Empty
PictureBox1.Invalidate()
End If
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If rubberBanding Then
rubberBand.Width = Math.Abs(e.X - startCorner.X)
rubberBand.Height = Math.Abs(e.Y - startCorner.Y)
rubberBand.X = Math.Min(e.X, startCorner.X)
rubberBand.Y = Math.Min(e.Y, startCorner.Y)
PictureBox1.Invalidate()
End If
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
rubberBanding = False
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As _
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Using pn As New Pen(rubberBandColor, 2) With {.DashStyle = _
Drawing2D.DashStyle.Dash}
e.Graphics.DrawRectangle(pn, rubberBand)
MyRect1 = New Rectangle(rubberBand.X, rubberBand.Y, _
rubberBand.Width, rubberBand.Height)
End Using
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) _
Handles Button1.Click
Dim bm As New Bitmap(PictureBox1.Image)
Dim bmTo As New Bitmap(PictureBox1.Image)
Using g As Graphics = Graphics.FromImage(bmTo)
Dim to_rect As New Rectangle(0, 0, PictureBox4.Width, _
PictureBox4.Height)
If aspect > 1 Then
to_rect.Height = CInt(to_rect.Height * aspect)
Else
to_rect.Width = CInt(to_rect.Width * aspect)
End If
g.DrawImage(bm, to_rect, MyRect1, GraphicsUnit.Pixel)
g.DrawRectangle(Pens.Red, to_rect)
PictureBox4.Image = bmTo
End Using
End Sub
End Class 0 |