Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using brushcopy

Status
Not open for further replies.

frank13

Programmer
Sep 11, 2005
2
CA
Hi, I have a large bmp which I load at run-time into a TBitmap. The background is pink but I have a bunch of images on that large bitmap. I can paint the entire pink background to white or any other colour using brushcopy.

What I would like to be able to do is be able to do the reverse, keep the pink but paint everything else, regardless of what colour the pixels are, to a single colour such as black.

Anyone know how I would do this?

Thank you
 
Hi,

Depending on how your image looks like, maybe the FloodFill method of TCanvas could help u...

else take a look at
.Canvas.copymode:=cmSrcAnd; // and/or cmMergePaint
with
.Canvas.CopyRect(..)

the idea is to copy your image on you image taking advantage of the copymode.. if u need a concrete exemple let me know i think i have one at home

hope this help
jb
 
Thanks for the response. Nope, floodfill won't help because the background colour is also the transparent colour of many of the images on that bitmap. So a floodfill wouldn't change the pink within those images.

I've been looking at copymodes but I admit my understanding of many of them is lacking even though that's probably where my answer lies. I have used copyrect to blit transparent images to the screen but this is a reverse problem. I want to keep the transparent colour (the pink) and change all the other colours to black.

Currently I'm using GetPixel-PutPixel but geez is that ever slow :)

 
this sounds like a mask. Investigate in the help file on how to create a masked bitmap from your existing bitmap. Masks are used to paint with transparency.
 
hi,

try this, working for me with d5


myfunction(clFuchsia,'C:\mybmp.bmp');

procedure TForm1.myfunction(clr:TColor;path:string);
var
MyRect:TRect;
BMSrc:Tbitmap;
BMTemp:Tbitmap;
begin
//Step 1 : Create bitmap
BMSrc:=TBitmap.Create;
BMTemp:=TBitmap.Create;
//Step 2 : Initialisation
BMSrc.LoadFromFile(path);
BMTemp.Assign(BMSrc);
MyRect:=Rect(0,0,BMSrc.Width,BMSrc.Height);
BMTemp.Canvas.Brush.Color:=clr;
BMTemp.Canvas.FloodFill(1,1,clr,fsBorder);
//Step 3 : apply mask
BMSrc.Mask(clr);
//Step 4 : Merge the 2 bitmap
BMTemp.Canvas.copymode:=cmSrcAnd;
BMTemp.Canvas.copyrect(MyRect,BMSrc.Canvas,MyRect);
//Step 5 : show it
Image1.Picture.Bitmap:=BMTemp;
//Step 6 : free mem
BMSrc.Free;
BMTemp.Free;
end;

jb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top