Best way to split up image into smaller pieces?

BlitzMax Forums/BlitzMax Beginners Area/Best way to split up image into smaller pieces?

Grisu(Posted 2006) [#1]
Hi!

I'd like to do a simple puzzle game.
For this I need to split up a original image of 340x340 pixels into 10x10 square blocks, 34 pixels each.

I need to be able to select each separate piece later on.
How would be the best way of doing this?

Thanks, Grisu


ImaginaryHuman(Posted 2006) [#2]
Use some scissors?

;-)


ImaginaryHuman(Posted 2006) [#3]
Or try LoadAnimImage()


Grisu(Posted 2006) [#4]
I want to create it in runtime!

Sure I know how to load multiple images from HDD Angel... :P

I already have the image in memory as I need it for other stuff, so how can I copy out multiple square images?


BlackSp1der(Posted 2006) [#5]
use PixmapWindow ?


Diablo(Posted 2006) [#6]
Have you tried somthing like this:
Rem
	Cut & Go
EndRem
SuperStrict 'FTW

SeedRnd(MilliSecs())

Graphics 800, 600

Const FRAMESX% = 10
Const FRAMESY% = 10

Global image:TImage = LoadImage("background1.png")
Global cutImage:TImage

Type TImageCutta

	Function CutImage:TImage(image:TImage, xTiles% = 2, yTiles% = 2)
	
		Local fWidth% = image.width / xTiles
		Local fHeight% = image.height / yTiles
		Local tTotal% = xTiles * yTiles
		
		Local cut:TImage = CreateImage(fWidth, fHeight, tTotal)
		
		Cls
		DrawImage image, 0, 0
		
		Local xx%, yy%, cc%
		For Local x% = 0 Until xTiles
		
			For Local y% = 0 Until yTiles
			
				xx = x * fWidth
				yy = y * fHeight
				
				GrabImage(cut, xx, yy, cc)
				
				cc:+ 1
			
			Next
			
		Next
		
		
		Return cut
	
	
	End Function

End Type

cutImage = TImageCutta.CutImage(image, FRAMESX, FRAMESY)

Global puzzle%[FRAMESX, FRAMESY]

For Local x% = 0 Until FRAMESX

	For Local y% = 0 Until FRAMESY
	
		puzzle[x, y] = Rand(0, (FRAMESX * FRAMESY) - 1)
		
	Next
	
Next

While Not KeyHit(KEY_ESCAPE)


 	Cls

	For Local x% = 0 Until FRAMESX

		For Local y% = 0 Until FRAMESY
		
			DrawImage cutImage, x * cutImage.width, y * cutImage.height, puzzle[x, y]
			

		Next
		
	Next
	
	Flip
	
Wend



Yan(Posted 2006) [#7]
img:TImage = LoadImage("image.png")
animg:TImage = LoadAnimImage(img.Lock(0, True, False), 34, 34, 0, 10)



Grisu(Posted 2006) [#8]
Thanks all!

This is the code I use now. Nothing seems to be faster / easier:

Graphics 800,600

Global PLATESIZE=68
Global PLATEMAX=340/PLATESIZE*340/PLATESIZE

Global img:TImage = LoadImage("media/1.jpg")
Global animg:TImage = LoadAnimImage(img.Lock(0, True, False), PLATESIZE, PLATESIZE, 0, PLATEMAX)

Global x:Int=0,y:Int=0
Global j:Int 
For Local i=0 To PLATEMAX-1
	DrawImage animg,x,y,i
	x=x+PLATESIZE+1
	j=j+1

    If j Mod (340/PLATESIZE) = 0 Then 
		x=0
		y=y+PLATESIZE+1
	EndIf  
Next 
Flip
WaitKey