23-01-18, 05:07 AM
السلام عليكم ورحمة الله وبركاته
تفضلي يا أختي آمنه، تحويل كود الجافا إلى كود فيجوال بيسك
تفضلي يا أختي آمنه، تحويل كود الجافا إلى كود فيجوال بيسك
كود :
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Using OpenFileDialog1 As New OpenFileDialog With {.Filter = "Images|*.png;*.jpg;*.jpeg;*.bmp;*.gif"}
If OpenFileDialog1.ShowDialog = vbOK Then
Dim file As String = OpenFileDialog1.FileName ' "bear.jpg"
Dim image As Image = image.FromFile(file) 'reading the image file
Dim rows As Integer = 4 'You should decide the values for rows and cols variables
Dim cols As Integer = 4
Dim chunks As Integer = rows * cols
Dim chunkWidth As Integer = image.Width / cols ' determines the chunk width and height
Dim chunkHeight As Integer = image.Height / rows
Dim count As Integer = 0
Dim imgs(chunks - 1) As Image 'Image array to hold image chunks
For x As Integer = 0 To rows - 1
For y As Integer = 0 To cols - 1
'Initialize the image array with image chunks
imgs(count) = New Bitmap(chunkWidth, chunkHeight)
' draws the image chunk
Dim gr As Graphics = Graphics.FromImage(imgs(count))
gr.DrawImage(image, New Rectangle(0, 0, chunkWidth, chunkHeight), New Rectangle(chunkWidth * y, chunkHeight * x, chunkWidth, chunkHeight), GraphicsUnit.Pixel)
count += 1
gr.Dispose()
Next
Next
MsgBox("Splitting done")
'writing mini images into image files
Dim dir As String = Application.StartupPath & "\Chunks\"
If Not IO.Directory.Exists(dir) Then IO.Directory.CreateDirectory(dir)
For i As Integer = 0 To imgs.Length - 1
imgs(i).Save(dir & "\img" & i & ".jpg")
Next
MsgBox("Mini images created")
End If
End Using
End Sub