Scale image ?

BlitzMax Forums/BlitzMax Programming/Scale image ?

Hi

Is there a method to scale an image ??? i have try resize
pixmap but i don't use pixmap , but timage.

Check out the "SetScale" command, it will change the size of the image being drawn to the display. Its a state machine too, so dont forget to reset it after you have used it like "SetScale 1.0,1.0".

Examples of use
SetScale 2.0,2.0 '2x the size
SetScale 6.0,6.0 '6x the size
SetScale 0.5,0.5 'Half size
SetScale 0.25,0.25 'Quater size
SetScale 1.0,1.0 'Normal size


Many thanks !

I hope that mark integrate this stuff ...

Hi :)

I have made a function to resize an image .... It's a little bit rock n roll :)
But it work :)

' ------------
' Open graphic
' ------------
Graphics 1024,768,0

Global MyIMage01:Timage=LoadImage("colourblind.jpeg")

Global MyIMage02:Timage=ResizeImage(MyIMage01,256,256)


' -------------
' The main loop
' -------------
While Not KeyHit(KEY_ESCAPE)
	Cls

	DrawImage MyIMage02,0,0
	
	' ------------------------
	' Swap buffer and flushmem
	' ------------------------
	Flip
Wend 


Function ResizeImage:Timage(Image:TImage,Tx:Int,Ty:Int)
	Local x
	Local y
	Local c
	Local Pixmap:TPixmap
	Local Duplicate:TPixmap
		
	Local Output:Timage

	Duplicate=CreatePixmap(ImageWidth(Image),ImageHeight(Image),PF_RGB888)
	Pixmap = LockImage(Image)
	
	For x = 0 To ImageWidth(Image) - 1
		For y = 0 To ImageHeight(Image) - 1
			
			c=ReadPixel(Pixmap, x, y)
			WritePixel(Duplicate, x,y,c)
			
		Next			
	Next

	UnlockImage(Image)
	Pixmap= Null
	
	
	Resized=ResizePixmap(Duplicate,Tx,Ty)
	
	Output=CreateImage(Tx,Ty)
	Pixmap=LockImage(Output)
	
	For x = 0 To Tx-1
		For y = 0 To Ty-1 
			c=ReadPixel(Resized, x, y)
			WritePixel(Pixmap, x,y,c)
		Next			
	Next

	UnlockImage(Output)
	
	Duplicate= Null	
	Pixmap= Null
	
	Return Output
End Function


Surely you don't have to do that one pixel at a time?

Surely you can access an image's pixmap by using the LockImage command. Then simple use the ResizePixmap command. Or have I got that wrong?

SetScale (covered in the Max2D documentation) is the global, realtime/runtime way to scale an image (using 3D acceleration), however if you want to resize an image permanently, you can do so on a pixmap using ResizePixmap (covered in the Pixmap documentation).

If you have another way to resize easily an image .... :) post it :)

Filax, why would you want to do this?

SetScale will scale the images (Textured Quads) as they are drawn.

If you have another way to resize easily an image .... :) post it :)
SkidRacer posted this in the code archive.
Function ResizeImage:TImage(image:TImage,width,height)
	Local pix:TPixmap=LockImage(image)
	pix=ResizePixmap(pix,width,height)
	UnlockImage(image)	
	Return LoadImage(pix)
End Function


Hum hum Thanks ! :) it's a really simple method !

It's a little bit obscur for me the difference between image and pixmap...

Hum hum Thanks ! :) it's a really simple method ! I don't understand
very well for the moment the difference between image and pixmap ...
Images are held on the gfx card, thus fast to draw to the display (fastest).
Pixmaps are held in system memory, thus need to be copied over to the gfx card before being drawn to the display (slower).

Images can't be altered, as gfx card memory tends to be faster to read from (drawing) then to write too (downloading a image from gfx card).
Pixmaps can be altered as you like as there held in system memory.

Its possible to convert a pixmap to an image via the image=loadimage(pixmap) command!.

Hum hum ok !