Page 1 of 1
Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 3:05 am
by coco2
Is it possible to resize an image to another existing one, or to the screen? I have looked at ResizeImage() and it does not do what I want. The reason I want to do this is to simulate a lower resolution in my game engine. ResizeImage() could do it if I create a new image each frame which is obviously not a good idea.
Edit: sorry my bad again I hope you don't mind my beginner questions
You can do this with DrawImage() by setting the width and height.
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 4:53 am
by Demivec
If using a screen do it with sprites and controling the zoom.
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 5:28 am
by coco2
I did it with DrawImage() but it takes huge amounts of CPU. EDIT: I will post up an example soon
EDIT: Please have a look at my example. Is there a faster way to do the resize? It's consuming a LOT of CPU to do this. Surely there is a faster way?
Code: Select all
EnableExplicit
Define.i Event, Quit
Quit = 0
InitSprite()
InitKeyboard()
CreateImage(0, 320, 240, 32)
OpenWindow(0, 0, 0, 640, 480, "Test Environment", #PB_Window_SystemMenu | #PB_Window_Maximize | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #False, 0 , 0, #PB_Screen_WaitSynchronization)
Repeat
; Draw the circle to the temp image buffer
StartDrawing(ImageOutput(0))
Box(0, 0, 320, 240, 8723235)
Circle(160, 120, 50, #Yellow)
StopDrawing()
; Copy the temp image buffer to the screen resizing it
StartDrawing(ScreenOutput())
DrawImage(ImageID(0), 0, 0, WindowWidth(0), WindowHeight(0))
; **********************************************************
; Why does this take so much CPU especially when maximised?
; **********************************************************
StopDrawing()
FlipBuffers()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape) : Quit = 1 : EndIf
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow : Quit = 1 : EndIf
Until Event = 0
Until Quit
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 6:36 am
by coco2
Is there a way to access the images and screen memory manually with ASM? I think I would need to rewrite this function to be faster.
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 8:34 am
by Fig
Like it was said before, use zoomsprite and sprite.
Each time you can avoid using stardrawing()/stopdrawing() in your main loop, it's better.
You should use it as few as possible.(once per loop is alright, no more)
Sprites are the fastest.
Code: Select all
EnableExplicit
Define.i Event, Quit
Quit = 0
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 640, 480, "Test Environment", #PB_Window_SystemMenu | #PB_Window_Maximize | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #False, 0 , 0, #PB_Screen_WaitSynchronization)
;create new sprite 0
CreateSprite(0,320,240)
;draw inside sprite 0 one time only
StartDrawing(SpriteOutput(0))
Box(0, 0, 320, 240, 8723235)
Circle(160, 120, 50, #Yellow)
StopDrawing()
Repeat
;zoom sprite
ZoomSprite(0,ScreenWidth(),ScreenHeight())
;display sprite
DisplaySprite(0,0,0)
FlipBuffers()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape) : Quit = 1 : EndIf
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow : Quit = 1 : EndIf
Until Event = 0
Until Quit
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 8:38 am
by coco2
Thank you Fig I should have tried myself. I looked at Sprite and thought it was wrong to Zoom a sprite 60 times a second but I guess that's what it's designed for? I guess the image functions are not designed for this task. Thanks again. EDIT: Thank you also Demivec
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 8:43 am
by Fig
Yes it's been designed for.
You can display thousandS of sprites without any problem.
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 11:29 pm
by coco2
That's good I assume a good game needs many sprites displayed. I have another problem now, I can't get the sprite to be transparent. When I try this code all I get is a black screen. Shouldn't it clear the sprite with a transparent box? Shouldn't there be a blue and a yellow circle?
Code: Select all
EnableExplicit
Define.i Event, Quit, Sprite
Quit = 0
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 640, 480, "Test Environment", #PB_Window_SystemMenu | #PB_Window_Maximize | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #False, 0 , 0, #PB_Screen_WaitSynchronization)
;create new sprite
Sprite = 257
CreateSprite(Sprite, 320, 240, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(Sprite))
Box(0, 0, 320, 240, RGBA(0,0,0,0))
Circle(100, 120, 10, #Blue)
StopDrawing()
StopDrawing()
Repeat
StartDrawing(ScreenOutput())
Circle(160, 120, 50, #Yellow)
StopDrawing()
;zoom sprite
ZoomSprite(Sprite,ScreenWidth(),ScreenHeight())
;display sprite
DisplayTransparentSprite(Sprite,0,0)
FlipBuffers()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape) : Quit = 1 : EndIf
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow : Quit = 1 : EndIf
Until Event = 0
Until Quit
Re: Resize one image to another existing one (or screen)
Posted: Tue Jan 10, 2017 11:56 pm
by coco2
I figured it out, I needed to specify the correct amount of alpha
EDIT: It doesn't do what I wanted it for anyway, you can't output a sprite to a sprite.
Re: Resize one image to another existing one (or screen)
Posted: Wed Jan 11, 2017 9:23 am
by Fig
I don't know what you really want, but i am sure you can do something else than puting a sprite in an other sprite to achieve your goal.
Think out of the box ^^
Re: Resize one image to another existing one (or screen)
Posted: Thu Jan 12, 2017 2:11 pm
by coco2
Yup, I was thinking wrong
You can do it just zooming sprites. And if I REALLY want to zoom standard drawing routines then I can draw to a sprite, zoom it then paste it in. Plus if I REALLY want to apply filters then I can access the video buffer directly. But I don't need to. I was just stuck in some wrong thinking. All sorted now, I needed to learn at some point.