dineshbajaj,
Here is a function that splits an image into an array of smaller images. In you pass in rows = 2 and columns = 2 you will get back four images, each a quarter of the original image, each representing a different quadrant of the image.
Private Function SplitImage(ByVal wholeImage As Image, ByVal rows As Integer, _
ByVal columns As Integer) As Image()
Dim cellWidth As Single = CType(wholeImage.Width / columns, Single)
Dim cellHeight As Single = CType(wholeImage.Height / rows, Single)
' Create an array of RectangleF to hold the RectangleFs
' that define parts (cells) of the wholeImage.
Dim rectangleFs((rows * columns) - 1) As RectangleF
' Fill RectangleFs array with RectangleF objects.
Dim currentRow As Single = 0
Dim currentColumn As Single = 0
Dim rectangleFIndex As Integer = 0
For currentRow = 0 To rows - 1
For currentColumn = 0 To columns - 1
Dim newRectangleF As New RectangleF()
newRectangleF.X = currentColumn * cellWidth
newRectangleF.Y = currentRow * cellHeight
newRectangleF.Width = cellWidth
newRectangleF.Height = cellHeight
rectangleFs(rectangleFIndex) = newRectangleF
rectangleFIndex += 1
Next
Next
' Create an array of Images to contain the images
' that will be created from the wholeImage.
Dim images(rectangleFs.GetLength(0)) As Image
' Fill images array with Images.
Dim i As Integer = 0
For i = 0 To rectangleFs.GetUpperBound(0)
Dim newBitMap As New Bitmap(CType(cellWidth, Integer), _
CType(cellHeight, Integer))
Dim bitMapGraphics As Graphics = Graphics.FromImage(newBitMap)
bitMapGraphics.Clear(Color.Blue)
bitMapGraphics.DrawImage(wholeImage, newBitMap.GetBounds(GraphicsUnit.Pixel), _
rectangleFs(i), GraphicsUnit.Pixel)
images(i) = newBitMap
Next
Return images
End Function
--
Mike
Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com