Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Copying pixels from one bitmap to another

This thread is locked; no one can reply to it. rss feed Print
Copying pixels from one bitmap to another
fatboy2
Member #8,239
January 2007

How do I copy a set of pixels from one bitmap to another.
I have a line on each of the 2 bitmaps. I want to be able to copy the line from bitmap1 to bitmap2 without erasing the line that is already there on bitmap2.
I tried reading the manual and masked_blit does not seem to work.

This is the code I am trying to write

BITMAP *draw = create_bitmap(640,480);
BITMAP *bmp = create_bitmap(640,480);
line (draw,10,10,500,10,makecol(255,255,255));
line (bmp,50,50,500,50,makecol(255,255,255));
masked_blit(draw,screen,0,0,0,0,640,480);
masked_blit(bmp,screen,0,0,0,0,640,480);

The problem I have is that only one of the lines copies. Please help to solve this problem.

Kris Asick
Member #1,424
July 2001

masked_blit() uses colour #0 as the transparent colour in 256 colour mode, and magic pink, which is makecol(255,0,255), for 15/16/24/32-bit modes. Thus if your background is black on your draw and bmp BITMAP objects, and you're using a colour depth above 8-bit, the black isn't considered transparent to masked_blit().

Try clearing the backgrounds of draw and bmp to 255,0,255 and see if that helps.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Paul whoknows
Member #5,081
September 2004
avatar

BITMAP *draw = create_bitmap(640,480);
BITMAP *bmp = create_bitmap(640,480);
clear_to_color(draw, makecol(255, 0, 255));
clear_to_color(bmp, makecol(255, 0, 255));
line (draw,10,10,500,10,makecol(255,255,255));
line (bmp,50,50,500,50,makecol(255,255,255));
masked_blit(draw,screen,0,0,0,0,640,480);
masked_blit(bmp,screen,0,0,0,0,640,480);

[EDIT]
Beaten!>:(

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

ImLeftFooted
Member #3,935
October 2003
avatar

Quote:

Try clearing the backgrounds of draw and bmp to 255,0,255 and see if that helps.

You really shouldn't be using 255,0,255. What you want to use is this little function:

int col = bitmap_mask_color(theBitmap);

BAF
Member #2,981
December 2002
avatar

You should do your masked_blit's to an intermediate buffer rather than directly to screen.

Go to: