PictureBox is a control for displaying pictures. Not a magic thing for
manipulating them with.
The GDI+ FAQ has information on how to draw an image and the Beginners Guide
to GDI+ has an article on how to use images.
Throw out the picturebox nonsense and use bitmaps and Graphics objects.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
[quoted text, click to view] "Mad Scientist Jr" <usenet_daughter@yahoo.com> wrote in message
news:1106923510.327990.207380@f14g2000cwb.googlegroups.com...
>I have a bitmap (32 pixels high, 8192 pixels wide) that contains 255
> images, each 32 pixels wide, that I would like to chop up into
> individual 32x32 bitmap files. Rather than spending hours in Paint or
> Photoshop I would like to do this programmatically. My code below
> attempts to load in the original bitmap, crop it at the desired
> location, and save it to the correct file. I don't think I'm doing this
> right, I tried messing with different picturebox properties/methods
> such as .SetBounds. I would either like to crop the full bitmap and
> save it, or copy the portion to a 2nd 32x32 bitmap and save it. Any
> help appreciated....
>
> sub BreakAllTiles()
> dim iLoop as int16
> for iLoop = 0 to 255
> call TileBreaker(iLoop)
> next
> end sub
>
> Sub TileBreaker(ByVal iImageNum As Int16)
> Dim iX As Int16
> Dim iY As Int16
> Dim pb1 As New PictureBox
> Dim pb2 As New PictureBox
> Dim sFile As String
> Dim sNumber As String
> pb1.Size = New Size(8192, 32) ' holds the bitmap with all the images
> pb2.Size = New Size(32, 32) ' holds the desired 32x32 square
> sFile = "C:\temp\Images\All255Images.bmp"
> pb1.Image = pb1.Image.FromFile(sFile) ' get the full image
> iX = 0 + (iImageNum * 32) ' calculate x position of the desired square
> iY = 0 ' y position is always zero in this case
> pb1.SetBounds(iX, iY, 32, 32) ' select the desired square - here we
> would like to crop pb1 at position (iX,iY) to size 32,32
> 'OR copy a 32x32 square of pb1 at (iX,iY), to pb2, and pb2.image.save
> sNumber = "000" & iImageNum.ToString
> sFile = "C:\temp\images\image" & sNumber.Substring(sNumber.Length - 3,
> 3) & ".bmp"
> pb1.Image.Save(sFile, System.Drawing.Imaging.ImageFormat.Bmp) ' save
> the cropped image
> end sub ' TileBreaker
>