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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles _ Button1.Click
ProgressBar1.Va lue = 0
ProgressBar1.St ep = 1
ProgressBar1.Ma ximum = 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(Environm ent.GetFolderPa th
_(Environment.S pecialFolder.De sktopDirectory) & "\images\test.b mp")
'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.FromIm age(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(bmp ToSplit, New Rectangle(0, 0, 8, 16), x, y, 8, 16,
GraphicsUnit.Pi xel)
x += 8
If x = 128 Then
x = 0
y += 16
End If
'save the newly created image
images(i).Save( Environment.Get FolderPath(Envi ronment.Special Folder.DesktopD i
rectory) & "\images\" & _ i & ".bmp", Imaging.ImageFo rmat.Bmp)
ProgressBar1.Pe rformStep()
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.FromIm age(bmpFromSpli tted)
For i As Integer = 0 To 255
'Now loop trough all the 256 files and put them at the original
location
g.DrawImage(Ima ge.FromFile(Env ironment.GetFol derPath
_(Environment.S pecialFolder.De sktopDirectory) & "\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("Splitti ng 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 [MVP]" <vb***@bellsout h.net> schreef in bericht
news:u0******** ******@TK2MSFTN GP15.phx.gbl...
Hi,
http://www.windowsformsdatagridhelp....32-51bf-4e9d-a
f43-fa9d76e54f15
Ken
---------------------
"Tamer Abdalla via DotNetMonster.c om" <u12711@uwe> wrote in message
news:556062972e 726@uwe... Hello, everyone!
I DO need some help in order to understand how to create graphics in
VB.NET.
I'm a little bit confused... I once knew a time when using Point & PSet
was
almost the only way to make some interesting apps which could tranform
images
(i.e. making saturation of colours "heavy", or gradually fade to
grayscale,
or "erasing" a colour... and so on), while nowadays it seems quite
impossible.
Now that I got .NET over VisualStudio I'm trying to figure out how to
make a
program that is the equivalent of "Hello, world!" speakin' in graphical
terms:
I need to split a B&W bitmap (W x H: 128 x 256 pixels) into 256
different pieces of it (W x H: 8 x 16), while saving them into 256 different
files.
HELP ME!
--
Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...b-net/200510/1