News:

Function Finder  Find all the functions within source code files

Main Menu

Grabbing AFX Images from an AFX formatted image.

Started by kevin, January 13, 2009, 06:57:28 AM

Previous topic - Next topic

kevin

 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


PlayBASIC Code: [Select]
   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




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

kevin

#1
 This version is for PB1.64i above.  In these version GetImage with automatically create an AFX surface when grabbing from an AFX surface.

PlayBASIC Code: [Select]
   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