提问人:HzCat 提问时间:11/7/2023 更新时间:11/14/2023 访问量:23
一个图像裁剪与 For Next 循环与多个 xy
one Image Cropping with For Next loop with muti xy
问:
Hey, Im New with VB.NET
我正在尝试裁剪 1 图像 300,300 到 36 PictureBox 50,50 在列表中使用 For Next 循环中的多个 X 和 Y
Was like this :
PicBoxs(0).Image = CropBitmap(bmp, 0, 0, 50, 50)
PicBoxs(1).Image = CropBitmap(bmp, 50, 0, 50, 50)
PicBoxs(2).Image = CropBitmap(bmp, 100, 0, 50, 50) /* before*/
PicBoxs(3).Image = CropBitmap(bmp, 150, 0, 50, 50)
PicBoxs(4).Image = CropBitmap(bmp, 200, 0, 50, 50)
比我尝试用 For 循环编码:
For i As Integer = 0 To PicBoxs.Count - 1
For j As Integer = 0 To 250 Step 50
For k As Integer = 0 To 250 Step 50 /* j for y and k for x*/
PicBoxs(i).Image = CropBitmap(bmp, k, j, 50, 50)
Next
Next
Next
我也用它来定位
For i As Integer = 0 To PicBoxs.Count -1
For j As Integer = 50 To 300 Step 50
For k As Integer = 50 To 300 Step 50
PicBoxs(i).Location = New Point(k, j)
Next
Next
Next
但我认为我走错了方向。谢谢。
答:
0赞
HzCat
11/14/2023
#1
哦,好吧,我现在知道了
Dim picsize As Integer = 75
Dim zeile As Integer = 4
Dim spalte As Integer = 4
For i As Integer = 0 To zeile - 1
For j As Integer = 0 To spalte - 1
Dim x As Integer = j * picsize
Dim y As Integer = i * picsize
Dim xlo As Integer = j * picsize + 50 'Location + (50,50) fangt nicht mit 0 an.
Dim ylo As Integer = i * picsize + 50
Dim index As Integer = i * spalte + j
Pics(index) = New Bitmap(CropBitmap(bmp, x, y, picsize, picsize))
PicBoxs(index).Location = New Point(xlo, ylo)
Next
Next
评论
0赞
Jeremy Caney
11/17/2023
感谢您对 Stack Overflow 社区的贡献。这可能是一个正确的答案,但提供代码的额外解释,以便开发人员能够理解你的推理,这将是非常有用的。这对于不熟悉语法或难以理解概念的新开发人员特别有用。为了社区的利益,您能否编辑您的答案以包含其他详细信息?
评论
i
i