|
-
Sep 18th, 2011, 01:13 AM
#1
Thread Starter
Lively Member
split image
Hello,
I want to make a picture splitter, this means when i have a picture from 64x64 it should split is to 4 images of 32x32
how will I code this?
Thanks,
Jimpie
-
Sep 18th, 2011, 01:36 AM
#2
Re: split image
You create a new Bitmap of the appropriate size, call Graphics.FromImage to create a Graphics object, then call Graphics.DrawImage to draw the appropriate part of the original Image onto the new Image. Do that four times and you've got your wish. You should read the documentation for Graphics.DrawImage to find the appropriate overload to call.
-
Sep 18th, 2011, 05:34 AM
#3
Thread Starter
Lively Member
Re: split image
 Originally Posted by jmcilhinney
You create a new Bitmap of the appropriate size, call Graphics.FromImage to create a Graphics object, then call Graphics.DrawImage to draw the appropriate part of the original Image onto the new Image. Do that four times and you've got your wish. You should read the documentation for Graphics.DrawImage to find the appropriate overload to call.
Hello,
I can't get it working, i've never worked with splitting bitmaps before. I tried diffrent things but I can't. Could you help a bit more?
Code:
Private Sub btnSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSplit.Click
Dim G As Graphics = Me.PictureBox2.CreateGraphics
Dim tileset As Bitmap
Dim newtileset As Bitmap
Dim iRect As Rectangle
Dim sRect As Rectangle
tileset = New Bitmap(PictureBox.Image)
For x = 0 To (tileset.Width / 32)
For y = 0 To (tileset.Height / 32)
iRect = New Rectangle(x * 32, y * 32, 32, 32)
sRect = New Rectangle(x * 32, y * 32, 32, 32)
G.DrawImage(tileset, iRect, sRect, GraphicsUnit.Pixel)
G = Graphics.FromImage(tileset)
newtileset = tileset
Next
Next
End Sub
-
Sep 18th, 2011, 08:31 AM
#4
Re: split image
 Originally Posted by jmcilhinney
call Graphics.FromImage to create a Graphics object
 Originally Posted by jimpie
Code:
Dim G As Graphics = Me.PictureBox2.CreateGraphics
Do you see a discrepancy there?
-
Sep 18th, 2011, 11:08 AM
#5
Thread Starter
Lively Member
Re: split image
 Originally Posted by jmcilhinney
Do you see a discrepancy there?
I can't get it work, its now giving just a transparent png file with size 32x32 
Code:
Private Sub btnSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSplit.Click
Dim png As Bitmap
Dim g As Graphics
Dim iRect As Rectangle
Dim sRect As Rectangle
g = PictureBox2.CreateGraphics
'our new file
png = New Bitmap(32, 32)
'create graphic object
iRect = New Rectangle(0, 0, 32, 32)
sRect = New Rectangle(32, 32, 32, 32)
g.DrawImage(PictureBox.Image, iRect, sRect, GraphicsUnit.Pixel)
g = Graphics.FromImage(png)
png.Save("test.png", ImageFormat.Png)
End Sub
-
Sep 18th, 2011, 12:41 PM
#6
Hyperactive Member
Re: split image
Take a look at this example.
-
Sep 18th, 2011, 12:46 PM
#7
Thread Starter
Lively Member
Re: split image
 Originally Posted by Ram2Curious
Take a look at this example.
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|