Solved

Transparent parts for Bitmaps in D1

Posted on 1998-11-25
2
189 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Downloading email attachments 2 79
select query - oracle 16 100
LAN or WAN ? 11 95
Delphi: ForceDirectory plain function 7 42
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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