The following provides a pretty simple function that creates dulled edge around an images alpha channel. Alpha Channel is support in 32bit mode. To create an image with Alpha channel use the new PrepareAFXIMage command. Then render to it as normally.
Use ARGB(A,R,G,B) to build colours with alpha channel
RGBA() reads the A channel from a ARGB colour value
[pbcode]
CreateImage 100,800,600
rendertoimage 100
shadebox 0,0,800,600,0,255,$80a0cc,$ff00ff
Height=100
Width=100
Createimage 1,Width,Height
Preparefximage 1
FillIMage(1)
Createimage 2,Width,Height
PrepareAFXimage 2
FillIMage(2)
do
drawimage 100,x,ypos,false
for xlp=50 to 700 step 200
drawimage 1,xlp,100,true
drawimage 2,xlp,200,true
next
sync
loop
Function FillIMage(ThisImage)
rendertoimage ThisIMage
w=GetIMageWidth(Thisimage)
h=GetIMageheight(Thisimage)
ellipse w/2,h/2,w/2,h/2,true
CreateImageAlphaChannelFilter(ThisImage)
rendertoscreen
endfunction
; This function dulls the pixels on the start/edn of each row of image
Function CreateImageAlphaChannelFilter(ThisImage)
if GetImageStatus(thisImage)=true
DestSurface=getsurface()
RgbMaskIMage ThisImage,$00ffffff
TransparentColour=GetImageMaskColour(ThisIMage) and $ffffff
RenderToImage ThisImage
Width=GetImageWidth(ThisImage)-1
Dim Row(Width)
For ylp=0 to getimageheight(ThisImage)-1
firstsolid=false
; copy a row of pixels to this array
For xlp=0 to width
Row(xlp)=FastPoint(xlp,ylp)
next
; scan row and set the first an last pixels
; of a row to 50% alpha..
For xlp=0 to Width
c=Row(xlp)
if C=TransparentColour
if xlp>0
oldc=Row(xlp-1)
if RgbA(OldC)=255
Row(xlp-1)=(oldc and $ffffff) or $80000000
endif
endif
AlphaLevel=$0000000
FirstSolid=false
else
if firstsolid=false
AlphaLevel=$80000000
else
AlphaLevel=$ff000000
endif
firstsolid=true
endif
Row(xlp)=C or AlphaLevel
next
; copy the row back to the image
For xlp=0 to Width
fastdot xlp,ylp,Row(xlp)
next
next
rendertoimage DestSurface
endif
EndFunction
[/pbcode]
Note: Today it's recommended users create AFX images in AFX format directly via CreateImage, rather than creating an image (Video/FX) and then converting it to AFX)
Hi,
I have version 1.48 but I cannot find anywhere, in help file, info about rgba or ARGB.
More, I cannot find any info about Blitimage.
Can you give me more info about these functions? Do they work in my version (compiler: V1.48, IDE: V.1.1.5.b2)
Thank you!
There in the latest beta V1.48C. See announcement [plink]here (http://www.underwaredesign.com/forums/index.php?topic=1536.0)[/plink].
For BlitImage use search in forums.
8 white filled circles (all the same) on a shaded ground. Where is the joke?
That's about it, it's not meant to be pretty example, it's a functional example. It demonstrates how that the transparency of each pixel can be individually controlled the alpha channel, in AFX surfaces.
[pbcode]
CreateImage 100,800,600
RenderToImage 100
ShadeBox 0,0,800,600,0,255,$80a0cc,$ff00ff
Height=100
Width=100
ink $808080
Createimage 1,Width,Height,2
FillIMage(1)
Createimage 2,Width,Height,8
FillIMage(2)
do
drawimage 100,x,ypos,false
for xlp=50 to 700 step 200
drawimage 1,xlp,100,true
drawimage 2,xlp,200,true
next
sync
loop
Function FillIMage(ThisImage)
rendertoimage ThisIMage
w=GetIMageWidth(Thisimage)
h=GetIMageheight(Thisimage)
ellipse w/2,h/2,w/2,h/2,true
CreateImageAlphaChannelFilter(ThisImage)
rendertoscreen
endfunction
; This function dulls the pixels on the start/edn of each row of image
Function CreateImageAlphaChannelFilter(ThisImage)
if GetImageStatus(thisImage)=true
DestSurface=getsurface()
rgbmaskImage ThisIMage,$00ffffff
TransparentColour=GetImageMaskColour(ThisIMage) and $ffffff
Width=GetImageWidth(ThisImage)-1
RenderToImage ThisImage
lockbuffer
NullPoint=Point(0,0)
For ylp=0 to getimageheight(ThisImage)-1
For xlp=0 to width
c=Point(xlp,ylp) and $ffffff
if c
fastdot xlp,ylp,c or lsl32(xlp,24)
endif
next
next
unlockbuffer
rendertoimage DestSurface
endif
EndFunction
[/pbcode]
(Code Corrected (2012 - Oct -9th) Old versions of PB would draw AFX surfaces with transparency always, now it's optional)