I am using the following function to combine several layers of tiles into one tile.
The first index of image array is the bottom layer. All images must be of the same size. For images with diferent sizes, the read-write pixel loop should be changed.
Jure
Function MakeBlendedImage:TImage(Image:TImage[]) If image.length=Null Then Return Local Pixmap:TPixmap=CopyPixmap(image[0].pixmaps[0]) Local R1,G1,B1,A1 'overlaying image Local R2,G2,B2,A2 'background image Local finalAlpha# For Local i=1 Until image.length If image[i]=Null Then Continue For Local x=0 Until pixmap.width For Local y=0 Until pixmap.height GetRGBAfromColorValue(ReadPixel(pixmap,x,y),R2,G2,B2,A2) GetRGBAfromColorValue(ReadPixel(image[i].pixmaps[0],x,y),R1,G1,B1,A1) finalAlpha=GetFinalAlpha(A1,A2) WritePixel(Pixmap,x,y, GetColorValueFromRGBA(GetFinalColor(R1,A1,R2,A2, finalAlpha), GetFinalColor(G1,A1,G2,A2,finalAlpha), GetFinalColor(B1,A1,B2,A2,finalAlpha),finalAlpha)) Next Next Next Function GetFinalColor(color1,alpha1, color2,alpha2, finalAlpha#) Return (alpha1*color1/finalAlpha + alpha2*color2*(255-alpha1)/finalAlpha/255.0) EndFunction Function GetFinalAlpha:Float(alpha1,alpha2) Return (255-(255-alpha1)*(255-alpha2)/255.0) EndFunction Return LoadImage(Pixmap) EndFunction
The first index of image array is the bottom layer. All images must be of the same size. For images with diferent sizes, the read-write pixel loop should be changed.
Jure