Hi,
to add to what Ken posted I created an example with explanation for you.
Place a button and two 128 x 256 picturboxes and a progressbar on a form.
Name the pictureboxes picOrg and picSplit. Create a directory images on your
desktop and place the file to split in it.
Next paste in the following code, for the explanation see the comments in
the code.
Hth Greetz Peter
'at the top of your form you need to import system.drawing
Imports System.Drawing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ Button1.Click
ProgressBar1.Value = 0
ProgressBar1.Step = 1
ProgressBar1.Maximum = 255
'Load the bitmap/image to split from it's location
'in my case a directory called images on the desktop
Dim bmpToSplit As New Bitmap(Environment.GetFolderPath
_(Environment.SpecialFolder.DesktopDirectory) & "\images\test.bmp")
'Create a new bitmap to check if the splitted parts are the same as the
original after the splitting
Dim bmpFromSplitted As New Bitmap(128, 256)
'create a graphics object to do the drawing
Dim g As Graphics
'create a 256 items containing image array (0-255)
Dim images(255) As Bitmap
Dim x, y As Integer
For i As Integer = 0 To 255
'Initialize each array item
images(i) = New Bitmap(8, 16)
'assign the image to the graphics object so it knows what
'it needs to draw on
g = Graphics.FromImage(images(i))
'get the correct part of the original image and draw it onto one of our
255
'small images
'If you'd translate this line of code into normal language it would be
something like
'take a 8 x 16 part of the original at location x,y and draw it onto or
new image beginning at
'location 0 , 0 and draw it with a width of 8 and height of 16
g.DrawImage(bmpToSplit, New Rectangle(0, 0, 8, 16), x, y, 8, 16,
GraphicsUnit.Pixel)
x += 8
If x = 128 Then
x = 0
y += 16
End If
'save the newly created image
images(i).Save(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDi
rectory) & "\images\" & _ i & ".bmp", Imaging.ImageFormat.Bmp)
ProgressBar1.PerformStep()
Next
'reset or x and y counter
x = 0
y = 0
'Now we're going to recreat the original image from all 256
'small images
'First assign the bmpFromSplitted bitmap to the graphics object so it knows
what
'it needs to draw on
g = Graphics.FromImage(bmpFromSplitted)
For i As Integer = 0 To 255
'Now loop trough all the 256 files and put them at the original
location
g.DrawImage(Image.FromFile(Environment.GetFolderPath
_(Environment.SpecialFolder.DesktopDirectory) & "\images\" & i & ".bmp"), x,
y)
x += 8
If x = 128 Then
x = 0
y += 16
End If
Next
'dispose the graphics object
g.Dispose()
'Load the original image and the image created from all small files
'in the pictureboxes
picOrg.Image = bmpToSplit
picSplit.Image = bmpFromSplitted
MsgBox("Splitting complete")
End Sub
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
Ken Tucker said: