469,623 Members | 908 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

split an image programmatically

Hi Everybody,

I need to split an image file(*.jpeg) programmatically to nine or more
equal parts.

Since, the code is meant to run on Windows Pocket PC 2002, I can only
use methods supported by the .Net Compact Framework.

Thanks in Advance,

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #1
2 6483
first calculate the different x,y positions you want to get from the source
image, then the height and with of every piece and use g.drawimage

Dim g As Graphics
Dim x(8) As Bitmap
for i as integer = 0 to 8
x(i) = New Bitmap(90, 90)
g = Graphics.FromImage(x(i))
g.DrawImage(PictureBox1.Image, New Rectangle(0, 0, 90, 90), x, y, 90, 90, _
GraphicsUnit.Pixel)
next

hth
"dineshbajaj" <di****@palewar-dot-com.no-spam.invalid> wrote in message
news:41********@Usenet.com...
Hi Everybody,

I need to split an image file(*.jpeg) programmatically to nine or more
equal parts.

Since, the code is meant to run on Windows Pocket PC 2002, I can only
use methods supported by the .Net Compact Framework.

Thanks in Advance,

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Nov 21 '05 #2
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
"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message news:Ok*************@TK2MSFTNGP10.phx.gbl...
first calculate the different x,y positions you want to get from the source
image, then the height and with of every piece and use g.drawimage

Dim g As Graphics
Dim x(8) As Bitmap
for i as integer = 0 to 8
x(i) = New Bitmap(90, 90)
g = Graphics.FromImage(x(i))
g.DrawImage(PictureBox1.Image, New Rectangle(0, 0, 90, 90), x, y, 90, 90, _
GraphicsUnit.Pixel)
next

hth


"dineshbajaj" <di****@palewar-dot-com.no-spam.invalid> wrote in message
news:41********@Usenet.com...
Hi Everybody,

I need to split an image file(*.jpeg) programmatically to nine or more
equal parts.

Since, the code is meant to run on Windows Pocket PC 2002, I can only
use methods supported by the .Net Compact Framework.

Thanks in Advance,

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by murrayatuptowngallery | last post: by
3 posts views Thread by Rob Meade | last post: by
3 posts views Thread by Kristof Thys | last post: by
2 posts views Thread by UJ | last post: by
1 post views Thread by ree321 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.