Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bitmap transparency (lack of)

Status
Not open for further replies.

sggaunt

Programmer
Jul 4, 2001
8,620
GB
My application needs to quickly display a number of bitmaps (and Icons), so rather than loading from file when required I load them all into an image list (VCL)
and then extract as required.
But I require the bitmaps to have a transparent background, in this example it is Black.
The problem is that they do not display transparently (I see the bitmaps on a black square)

The image list is setup as follows:-
BkColor = ClBlack
BlendColor = ClNone
Drawing Style = dsTransparent
ImageType = itImage
Masked = false


The following code loads the Imagelist 'ActorImages'
I am using addmasked as this should force transparency ??

Code:
procedure TForm1.LoadActors(FName: TFilename);
var Bmp: TBitMap;
    Temp: string;
    A: integer;
begin
   ActorImages.Clear;
   Bmp := TBitMap.Create;
   for a := 0 to NumberofBMs -1 do
        begin
           Temp := FName;
           Temp := changefileext(Temp,'');
           Bmp.LoadFromFile(Temp + inttostr(a)+'.bmp');
           ActorImages.AddMasked(Bmp, $00000000);
       end;
   Bmp.Free;
end;


The following code creates objects (both types) dynamically from a file stream, and extracts the associated images from the imagelists (one for icons one for bitmaps).
As you can see I have tried to force transparency at this point, still no luck!

Code:
constructor TThings.CreateFromStream(Fs : TFileStream );
begin
   inherited Create;
   ReadFromStream(Fs);
   objectico := TImage.create(objectico);
        with objectico do
           begin
              if objtype = inanimate then
                  begin
                     Enabled := True;
                     Width := 32;
                     Height := 32;
                     Top  := YPos;
                     Left := XPos;
                     Form1.ImageList.GetIcon(ImageIndex[0], Picture.Icon);
                     Tag := index;
                     OnMouseDown := MouseDown;
                     OnMouseMove := MouseMove;
                     OnMouseUp := MouseUp;
                     Hint := ObjectName;
                     ShowHint := True;
                  //   PopUpMenu := Menu;
                  end
             else
                  begin
                     Enabled := True;
                     Width := 128;
                     Height := 128;
                     Top := 240;
                     Left := 650;

                     Form1.ActorImages.GetBitmap(ImageIndex[0], Picture.BitMap);

                     Picture.Bitmap.TransparentColor := $00000000;
                     Picture.Bitmap.Transparent := true;
                     Tag := index;
                  end
      end;
end;

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Cheers
I will have a look (a lot to work through), this problem has been on the back burner for a couple of years now I need to sort it.

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Ok Fixed it (not from the link just tried a few more things)
Fix [simplified version]

Code:
 objectico := TImage.create(objectico);
        with objectico do
           begin  
              Form1.ActorImages.GetBitmap(ImageIndex[0], Picture.BitMap);
              Picture.Bitmap.TransparentMode := TmAuto;       
            [s] Picture.Bitmap.Transparent := true; [/s]
           [red]Transparent := True;[/red] 
              Tag := index;  
 end;

The trick seems to be to make the parent object transparent, perhaps its (default) non transparency is inherited ?
The change to Auto transparency is not part of the fix just simplifies making the bitmaps.

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top