Solved

Transparent parts for Bitmaps in D1

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

Technology Partners: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

622 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