UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on January 13, 2009, 06:57:28 AM

Title: Grabbing AFX Images from an AFX formatted image.
Post by: kevin on January 13, 2009, 06:57:28 AM
 The following example shows how you can grab Animation frames from an AFX (FX images with Alpha Channel) surface.  In this example the code cuts the PB banner logo into a bunch of strips, then renders them.  The interesting thing about this demo, is that the strips retain the Alpha channel.


This version is for PB V1.64h


[pbcode]

   cls 255

   file$="playbasicsig2.png"
   LogoImage=LoadNewAFXImage(File$)
   drawimage LogoImage,100,100,true


   StripHeight=4

   Width=getImageWidth(logoIMage)
   H=GetimageHeight(logoImage)
   
   Dim Strips(h)


   Xpos=100
   ypos=200
      
   
   rendertoimage LogoIMage
   For lp=0 to h-1 step StripHeight
      Thisframe=NewAFXimage(Width,StripHeight)
      GetImage ThisFrame,0,lp,Width,lp+StripHeight
      Strips(lp)=Thisframe
   Next


   rendertoscreen

   For lp=0 to h
      Thisframe=Strips(lp)   
      if ThisFrame   
         drawimage ThisFrame,Xpos,Ypos+(lp*2),true   
      endif
   next
   
   Sync
   waitkey


// This function creates a AFX formatted image the size of the frame we're going to be grabbing
Function NewAFXimage(Width,Height)
   ThisImage=GetFreeImage()
   CreateFXimageEx Thisimage,Width,Height,32
   prepareafximage Thisimage
EndFunction ThisImage

[/pbcode]

PB logo (With alpha channel) attached.


NOTE: This code is no longer need.  GetImage will automatically create an AFX formatted image when grabbing from an AFX formatted surface
Title: Re: Grabbing AFX Images from an AFX formatted image.
Post by: kevin on January 13, 2009, 07:01:29 AM
 This version is for PB1.64i above.  In these version GetImage with automatically create an AFX surface when grabbing from an AFX surface.

[pbcode]

   cls 255

   file$="gfx\playbasicsig2.png"
   LogoImage=LoadNewAFXImage(File$)
   drawimage LogoImage,100,100,true


   StripHeight=4

   Width=getImageWidth(logoIMage)
   H=GetimageHeight(logoImage)
   
   Dim Strips(h)


   Xpos=100
   ypos=200
      
   
   rendertoimage LogoIMage
   For lp=0 to h-1 step StripHeight
      ThisFrame=GetFreeImage()
      GetImage ThisFrame,0,lp,Width,lp+StripHeight
      Strips(lp)=Thisframe
   Next


   rendertoscreen

   For lp=0 to h
      Thisframe=Strips(lp)   
      if ThisFrame   
         drawimage ThisFrame,Xpos,Ypos+(lp*2),true   
      endif
   next
   
   Sync
   waitkey
[/pbcode]