News:

Function Finder  Find all the functions within source code files

Main Menu

Convert MASKCOLOUR images to ALPHA CHANNEL

Started by kevin, February 28, 2023, 06:41:03 AM

Previous topic - Next topic

kevin

Convert MASKCOLOUR images to ALPHA CHANNEL

    Te purpose of this source code is to convert an image from mask colour transparency to Alpha channel transiency.    You could then save the image out using the freeimage library or us it in your scene.  

     NOTE:  The conversion function assumes the top left hand pixel is the ask colour in the image you pass it.. 


PlayBASIC Code: [Select]
; PROJECT : Converting Mask Colour To Alpha Channel
; AUTHOR : Learn To Code PlayBASIC
; CREATED : 27/02/2023
; EDITED : 28/02/2023
; ---------------------------------------------------------------------


SrcIMAGE =loadnewFXIMage("build2.bmp")

DestIMAGE=ConvertMaskColourToAlphaChannel(SrcImage)



do
cls $80ff40
drawimage DestIMAGE,mousex(),mousey(),true
sync
loop spacekey()




Function ConvertMaskColourToAlphaChannel(SrcImage)

local w=getimageWidth(SrcImage)
local h=getimageHeight(SrcImage)

//
local oldinkmode=getinkmode()
local oldsurface=getsurface()
rendertoimage SrcIMAGE


// OR all the Alpha channel bits
inkmode 1+512
boxc 0,0,w,h,true, $ff000000


local SrcMaskCOLOUR = point(0,0)


// create a new AFX image the same size are the source
DestIMAGE =NewFXIMAge(w,h,true)

rendertoimage DestIMAGE

// set the MASK colour and kill the ALPHA level
cls SrcMaskCOLOUR and $00ffffff

// draw the src image onto the destination
imagemaskcolour SrcImage, SrcMaskCOLOUR
drawimage SrcImage,0,0,true

; restore global state
inkmode OldInkMode
rendertoimage oldsurface

EndFunction DestImage







  Attached is a version with media that you can run.