Solved

Transparent parts for Bitmaps in D1

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now