Save a portion of a picturebox to a .bmp file?

LorgonJortle

Newcomer
Joined
Nov 22, 2009
Location
Maine, USA
Howdy there!
I've a picturebox that holds a rather large image. I was wondering if it was possible, with the right code, to save a portion of the image to a .bmp file. For example, (This is for my map editor) they load a large bitmap of their map, and want it cut into tiles of 32x32. Is this possible in VB.NET, and if so, may I have a point in the right direction?

Note: I'm rather new to VB.NET.

Thanks for any help,

LJ
 

snarfblam

Ultimate Contributor
Joined
Jun 10, 2003
Location
USA
Well, first of all, let's take the picture box out of the equation. What you're really after is a part of the image it contains, rather than the picture box itself (which has a border and could be obscured by another window), right?

First you would want to create a new Bitmap object, then create a Graphics object for that Bitmap. The Graphics object permits you to draw to the new Bitmap. Get the image that is hosted in the picture box and use Graphics.DrawImage to draw a portion of the original image to the new Bitmap. Now you can save the Bitmap. Make sure to dispose of the Bitmap and Grapdhics when you no longer need them.

I recommend using MSDN or Google to look up the documentation on these classes for the specifics.
 
Top Bottom