Advertisement Jump to content
Sign in to follow this  

[.net] Split a large image into smaller ones [SOLVED]

This topic is 4000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. I need some help with some C# image processing. I have a large image that I wish to split into smaller tiles (images are usually over 4000 pixels wide, 3000 high, and split them into tiles of about 500 by 500). I tried looking through the Image class, Bitmap class and I really couldn't find any functions that return sections of an image (other than pixels). I was just hoping there was some kind of function where I could specify the top left corner and the bottom right corner and it would return that region so I could save it. Do you know of any such functions that can do this? I really don't want to get each pixel and then create Bitmaps/Images from that (although it is easy, its just a pain). [Edited by - davek20 on February 11, 2008 8:26:44 AM]

Share this post

Link to post
Share on other sites
No, I don't think there is any such function. You need to create a new bitmap and then copy the part of the image you want on there. There's a simple way to do that with the drawing classes though:

// assuming tile size is 32 by 32
Bitmap newBitmap = new Bitmap(32,32);
using (Graphics g = Graphics.FromImage(newBitmap))
Rectangle destRect = new Rectangle(0,0,32,32);

// determine source rectangle somehow

g.DrawImage(sourceImage, destRect, sourceRect, GraphicsUnit.Pixel)

Share this post

Link to post
Share on other sites
Yup - Check out the Bitmap.Clone function. Load your huge image into as a Bitmap class, then Bitmap.Clone() will take whatever subimage you want and create a new Bitmap class.


Dim bmOriginal as New Bitmap("MyFileIsWayToHuge.bmp")
Dim bmTile1 As Bitmap = bmOriginal.Clone(0, 0, 500, 500)
'create more tiles...
'delete this huge image from memory
bmOriginal = Nothing

Not sure if you are using DirectX, but just an FYI textures are beneficial at certain sizes. 32px, 64px, 128px, 256px, 512px are all great texture sizes for DirectX.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!