Solved

Transparent parts for Bitmaps in D1

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

Independent Software Vendors: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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