Page 1 of 1
copy a sprite to an image ...
Posted: Sat Jun 07, 2025 10:35 am
by marc_256
Hello,
Win 10, [PB5.73 x64]
I need to copy a sprite to an image,
I found CopySprite (Sprite1, Sprite2)
But what is the best way to copy sprite to an image ?
I like to make a procedure CopySpriteToImage (Sprite#, Image#)
Thanks,
Marc
Re: copy a sprite to an image ...
Posted: Sat Jun 07, 2025 11:47 am
by Fred
SpriteOutput() + GrabDrawingImage()
Re: copy a sprite to an image ...
Posted: Sat Jun 07, 2025 3:46 pm
by infratec
Code: Select all
Procedure.i CopySpriteToImage(Sprite.i, Image.i)
Protected Result.i
If IsSprite(Sprite)
If StartDrawing(SpriteOutput(Sprite))
Result = GrabDrawingImage(Image, 0, 0, SpriteWidth(Sprite), SpriteHeight(Sprite))
StopDrawing()
EndIf
EndIf
ProcedureReturn Result
EndProcedure
But not tested, and I don't know what happends to the transparancy.
Re: copy a sprite to an image ...
Posted: Sat Jun 07, 2025 4:21 pm
by RASHAD
Quick hack
SubSystem Directx9
Nothing new from Fred and infratec but I am sure it works
Code: Select all
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
End
EndIf
Procedure Sprite2Image(sprite,img)
If IsSprite(sprite)
StartDrawing(SpriteOutput(sprite))
DrawingMode(#PB_2DDrawing_AllChannels )
GrabDrawingImage(img,0,0,SpriteWidth(0),SpriteHeight(0))
StopDrawing()
SaveImage(img,GetTemporaryDirectory()+"test.bmp")
Else
End
EndIf
EndProcedure
If OpenScreen(800, 600, 32, "Sprite")
; Load our 16 bit sprite (which is a 24 bit picture in fact, as BMP doesn't support 16 bit format)
;
LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp",#PB_Sprite_AlphaBlending)
Sprite2Image(0,0)
Else
MessageRequester("Error", "Can't open a 800*600 - 32 bit screen !", 0)
EndIf
Re: copy a sprite to an image ...
Posted: Mon Jun 09, 2025 11:57 am
by marc_256
Hi,
thanks guys for the tips,
But stupid me ...
I wrote an image rotation procedure
but the result of the rotated pixels was not so good ...
So, I wanted to use the RotateStrite to rotate the sprite and copy this to an Image,
but didn't work with SpriteOutput() + GrabDrawingImage()
The Sprite is only rotated on the screen and not in the memory ...
What I did now is to :
- Draw all on the Sprite
- Rotate Sprite
- Draw Sprite on the Screen
- and use GrabSprite ()
With SpriteQuality () the result is not 100%, but I can life with it
Thanks,
Marc