Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » how to remove background from bitmap ?

This thread is locked; no one can reply to it. rss feed Print
how to remove background from bitmap ?
Chaos Maker
Member #12,260
September 2010

im trying to make an map editor, but my sprites are with background '~'
look
{"name":"AllegroLol.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/4\/14aa8b3b9426145a87772519074ea52e.png","w":817,"h":637,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/4\/14aa8b3b9426145a87772519074ea52e"}AllegroLol.png
AllegroLol2.png
{"name":"AllegroLOLLOLOLOL.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/e\/7eb5fcfd88642d8c620f3e869c447012.png","w":263,"h":98,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/e\/7eb5fcfd88642d8c620f3e869c447012"}AllegroLOLLOLOLOL.png
HOW TO REMOVE THE TROLL BACKGROUND ?

jhetfield21
Member #12,379
November 2010

I'm a newbie as far as this library is concerned but I'm gonna go on a limb here.If you are blitting the cursor on the frame buffer then it's not difficult.

It puzzled me too.You have to make the background of the cursor icon a shade of pink(R:255,G:0,B:255) so that it is recognized by certain blit functions as a masked color,a kind of transparent.

If you are using allegro 4.2 then after painting the white background of the cursor pink in the RGB mentioned then load it and use maskedblit().It will just paint the cursor without the background.If you are using allegro5 then you need to load it to an ALLEGRO_BITMAP* and then use the al_convert_mask_to_alpha(cursoricon,al_map_rgb(255,0,255)) or sth like that to turn the pink into a transparent color and convert the whole bitmap once and for all.Then just al_draw_bitmap as you did before.

The only problem you might face is if you've made the palette yourself or even if you use the standar and the background color is also used in the part of the bitmap you want to blit then it might be a problem.You're just gonna have to check for it.
The lasso tool in Paint.NET or Photoshop is a good idea for this if you want to avoid the fuss.just cut what you want and put it inside a new file with pink background.the only defect is its very easy to cut a part that is rough on the edges literally.

Chaos Maker
Member #12,260
September 2010

im using allegro 4.4.0.1
i've allegro 5 here, but i cant install D:
EDIT========================
OH THANKS THANKS THANKS THANKS THANKS THANKS THANKS THANKS THANKS THANKS!
:D
i was changed the background color to pink and now my sprites is so perfect!

jhetfield21
Member #12,379
November 2010

4.4 is as someone else told me recently an updated 4.2 so masked blit it is.just make sure of the pink

What OS?if linux i just did it last night so i might be able to help you.if windows msvc maybe?in which case there is a video in youtube that is very helpful.

check pm

type568
Member #8,381
March 2007
avatar

As an option, try printing these images using putpixel and getpixel, while ignoring the unwanted color. This may hurt the performance if abused.

jhetfield21
Member #12,379
November 2010

yeah but ignoring the unwanted color doesn't mean that the only thing left out will be the background.it depends on the picture.i did it before i tried the way i said above and it screwed up the bitmap i was using.it left out portions of the region of the bitmap i wanted to blit.and like you said it hurts performance.just making the unwanted region pink is all you need and then masked blit takes it from there and delivers.

type568
Member #8,381
March 2007
avatar

Fill your images background with an unused color. Typically it's brightest pink.

LennyLen
Member #5,313
December 2004
avatar

Another option is to use RGBA bitmaps, and give your background pixels an alpha of 0. Then it doesn't matter what colour they are.

type568
Member #8,381
March 2007
avatar

LennyLen said:

Another option is to use RGBA bitmaps, and give your background pixels an alpha of 0. Then it doesn't matter what colour they are.

Ya, knew there's gotta be a CPU saving solution. Though I never got that "far".. However, if you whore performance with 16bit for some other reason, it won't work :P

Go to: