1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
Public Class Form2
Private RognageImages As New List(Of Bitmap)
Private GrandImage As Bitmap = Nothing
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Panel1.AutoScroll = True
Panel2.AutoScroll = True
picSource.Location = New Point(0, 0)
picSource.Size = New Size(20, 20)
picSource.SizeMode = PictureBoxSizeMode.AutoSize
picDestination.Location = New Point(0, 0)
picDestination.Size = New Size(20, 20)
picDestination.SizeMode = PictureBoxSizeMode.AutoSize
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
picSource.Image = My.Resources.Penguins
End Sub
Private selRect As Rectangle = Rectangle.Empty
Private startPoint As Point
Private Sub picSource_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSource.MouseDown
If e.Button = MouseButtons.Left Then
startPoint = e.Location
selRect.Location = startPoint
picSource.Invalidate()
End If
End Sub
Private Sub picSource_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSource.MouseMove
If e.Button = MouseButtons.Left Then
selRect.Width = e.X - startPoint.X
selRect.Height = e.Y - startPoint.Y
picSource.Invalidate()
End If
End Sub
Private Sub picSource_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSource.MouseUp
If e.Button = MouseButtons.Right Then
selRect.Width = e.X - startPoint.X
selRect.Height = e.Y - startPoint.Y
picSource.Invalidate()
PerformCopy()
selRect = Rectangle.Empty
End If
End Sub
Private Sub picSource_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picSource.Paint
Dim gr As Graphics = e.Graphics
Using selectionPen As New Pen(Brushes.Red, 1.0)
gr.DrawRectangle(selectionPen, selRect)
End Using
End Sub
Private Sub PerformCopy()
Dim sourcebmp As New Bitmap(picSource.Image)
Dim destinationbmp As New Bitmap(selRect.Width, selRect.Height)
Dim gr As Graphics = Graphics.FromImage(destinationbmp)
Dim destinationrectangle As New Rectangle(0, 0,
selRect.Width,
selRect.Height)
gr.DrawImage(sourcebmp, destinationrectangle,
selRect, GraphicsUnit.Pixel)
'Assemblage
RognageImages.Add(destinationbmp)
Dim largeur As Integer = RognageImages.Max(Function(o) o.Width)
Dim hauteur As Integer = 0
For Each item As Bitmap In RognageImages
hauteur += item.Height
Next
GrandImage = New Bitmap(largeur, hauteur)
Dim grfxBig As Graphics = Graphics.FromImage(GrandImage)
Dim x, y As Integer
x = 0 : y = 0
For i As Integer = 0 To RognageImages.Count - 1
grfxBig.DrawImage(RognageImages(i), x, y)
y += 10 + RognageImages(i).Height
Next
' Set the drawn "big" destination bitmap as the image of the second PictureBox
picDestination.Image = GrandImage
End Sub
End Class |
Partager