1 2 3 4 5 6 7 8 9 10 11 12 13
| Dim img As New Bitmap(FilePath)
For i As Integer = 0 To NumericUpDown1.Value - 1
For y As Integer = 0 To NumericUpDown2.Value - 1
Dim r As New Rectangle(i * (img.Width / CInt(NumericUpDown1.Value)), y * (img.Height / CInt(NumericUpDown2.Value)), img.Width / CInt(NumericUpDown1.Value), img.Height / CInt(NumericUpDown2.Value))
cropImage(img, r).Save(Path.Combine(folder.SelectedPath, "SplitImage-" & CInt(i) & "-" & CInt(y) & ".png"), ImageFormat.Png)
Next
Next
Private Shared Function cropImage(ByVal img As Image, ByVal cropArea As Rectangle) As Image
Dim bmpImage As New Bitmap(img)
Dim bmpCrop As Bitmap = bmpImage.Clone(cropArea, System.Drawing.Imaging.PixelFormat.DontCare)
Return CType(bmpCrop, Image)
End Function |
Partager