Solved

Transparent parts for Bitmaps in D1

Posted on 1998-11-25
2
190 Views
Last Modified: 2010-04-04
I'm using Delphi 1 and I was wondering if anyone could supply
my with some source code that would show me how to bring
a bitmap onto my form and not display one of the colors in the
bitmap, so that I can see what would normally be hidden
by that color.  It also needs to be done quickly.

Thanks,
JBreits
0
Comment
Question by:JBreits
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1347853
Well, it can be done very easily, but the speed is important... Here is something to try...

function DoTrans(DestForm : TForm; Bmp : TBitmap; Col : TColor) : TBitmap;
var
  x,y : Integer;
  B : TBitmap;
begin
  B := TBitmap.Create;
  B.Assign(Bmp);
  try
    for y := 0 to Bmp.Height - 1 do
      for x := 0 to Bmp.Width - 1 do
        if Bmp.Canvas.Pixels[x,y] = Col then
          B.Canvas.Pixels[x,y] := DestForm.Color
        else
          B.Canvas.Pixels[x,y] := Bmp.Canvas.Pixels[x,y];
    Result.Assign(B);
  finally
    B.Free;
  end;
end;

Let's say you want to have the color red transparent...

var
  bmp : TBitmap;
begin
 //Create the bitmap and all other stuff you want...
  bmp := DoTrans(Form1, bmp, clRed);
  Form1.Canvas.Draw(100,100, bmp);
//Free the bitmap and all the stuff...
end;

Try it out and tell me how it works...

Cheers,
Viktor
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1347854
Here is an example... I cahgned the function and a bit of the code...

var
      bmp : TBitmap;
procedure DoTrans(DestForm : TForm; var Bmp : TBitmap; Col : TColor);
var
      x,y : Integer;
begin
      for y := 0 to Bmp.Height - 1 do
            for x := 0 to Bmp.Width - 1 do
                  if Bmp.Canvas.Pixels[x,y] = Col then
                        Bmp.Canvas.Pixels[x,y] := DestForm.Color;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
            DoTrans(Form1, bmp, clBlack);
         Canvas.Draw(100,100, bmp);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
      bmp := TBitmap.Create;
   bmp.LoadFromFile('C:\windows\desktop\wow.bmp');

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
      bmp.Free;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
      Edit1.Text := Format('%d',[Canvas.Pixels[x,y]]);
end;

Hope this helps...

Cheers,
Viktor
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 90
error 1.1 400 Bad request idhttp delphi 18 199
Delphi IDE crash without error message ... 7 113
creating threads in delphi 1 157
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question