copy a sprite to an image ...

Just starting out? Need help? Post your questions and find answers here.
marc_256
Addict
Addict
Posts: 841
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

copy a sprite to an image ...

Post 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
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Fred
Administrator
Administrator
Posts: 18199
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: copy a sprite to an image ...

Post by Fred »

SpriteOutput() + GrabDrawingImage()
infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: copy a sprite to an image ...

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: copy a sprite to an image ...

Post 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
Egypt my love
marc_256
Addict
Addict
Posts: 841
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: copy a sprite to an image ...

Post 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 ... :oops: :oops:


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 :mrgreen:



Thanks,
Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Post Reply