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
Printable View
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
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
Quote:
Originally Posted by jmcilhinney
Do you see a discrepancy there?Quote:
Originally Posted by jimpie
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
Take a look at this example.