BMP transparency

Post your coding questions such as 'how to' here.
Post Reply
Arch-Stalker
Newcomer
Posts: 2
Joined: Sun Nov 09, 2008 1:36 pm

BMP transparency

Post by Arch-Stalker »

Ni Hao all

I decided to try out this nifty looking program, but ran in to troubles right away: I want to create my own graphics, but I can't make images with transparent background. I know how to make gifs with transparent background, but that does not help much. Google tells me that "you must make sure that the bitmap has been converted to Indexed 256 colour". I am using Adobe Photoshop 7.0 and I can find the option of coverting the image into indexed color, but I can't find the option for 256 colors and whatever I try gets the white background.

I realise this is probably the silliest question in the forums, but I would appreciate it if someone would help me.

Thanks for any help
I'm here to gather intelligence
I'm in great need of intelligence
Koodiapina
Forum Veteran
Posts: 2396
Joined: Tue Aug 28, 2007 4:20 pm

Re: BMP transparency

Post by Koodiapina »

CoolBasic doesn't support transparency.
TheFish
Developer
Developer
Posts: 477
Joined: Mon Aug 27, 2007 9:28 pm
Location: Joensuu

Re: BMP transparency

Post by TheFish »

Or actually CoolBasic doesn't support image that's only partially transparent.
You can use 'drawghostimage' command to draw a transparent image, or you can use 'maskimage' to make certain color "dissappear" from the image. In case you need to make a partially transparent background, you can make 2 images. In the first image, you just draw the areas that are supposed to be transparent and in the second image you draw the parts that are supposed to show up normally, and draw the transparent parts in the mask color. In your game you first use that 'drawghostimage' to draw the first image and then draw the second normally, using 'maskimage' to it (in that order, because if you draw the second image first, it will go under the first image).
CoolBasic henkilökuntaa
Kehittäjä
atomimalli
Moderator
Moderator
Posts: 227
Joined: Wed Aug 29, 2007 3:55 pm

Re: BMP transparency

Post by atomimalli »

Black(0,0,0) is coolbasic's default maskcolour.
You simply need to draw black where you want it to be transparent and save it as bmp or png, gif isn't supported.

You can set your own maskcolor for image like this:

Code: Select all

img=LoadImage("media/zerorun1.bmp")'load image with magenta background

DrawImage img,0,0'draw it
DrawScreen'updete screen
WaitKey

MaskImage img,255,0,255'change mask
DrawImage img,0,0'draw it
DrawScreen'updete screen
WaitKey
Coolbasic doesn't support alphatransparency.
Arch-Stalker
Newcomer
Posts: 2
Joined: Sun Nov 09, 2008 1:36 pm

Re: BMP transparency

Post by Arch-Stalker »

Thank you immensely for the quick advice. A very simple thing as I suspected, just got caught looking at the wrong direction :)

Thanks again to all!

Now I will go forth and wrestle my next problem that already surfaced :-P
I'm here to gather intelligence
I'm in great need of intelligence
Post Reply