Recent

Author Topic: image in timage compoent won't go to transparent!  (Read 3246 times)

Mariner1

  • Newbie
  • Posts: 1
image in timage compoent won't go to transparent!
« on: July 05, 2017, 05:39:01 am »
Hi All!  New to all this. I put a timage on a form, loaded a bitmap, set transparent to true but  don't get a transparent background. Can someone set me right on this? Thanks.

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: image in timage compoent won't go to transparent!
« Reply #1 on: July 05, 2017, 06:46:48 am »
Hello Mariner1,
Welcome to the forum.

Please provide your code and the image for use to check. It could be something wrong with your code or the image.

You can download and try my transparent.zip. I tested on Linux64, it worked correctly opening transparent png file.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, Forms, Graphics, Dialogs, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     btnBackground: TColorButton;
  16.     btnLoad: TButton;
  17.     Image1: TImage;
  18.     OpenDialog1: TOpenDialog;
  19.     procedure btnBackgroundColorChanged(Sender: TObject);
  20.     procedure btnLoadClick(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.btnLoadClick(Sender: TObject);
  34. begin
  35.   if not(OpenDialog1.Execute) then Exit;
  36.   try
  37.     Image1.Picture.LoadFromFile(OpenDialog1.FileName);
  38.   except
  39.     on E: Exception do
  40.       ShowMessage('Cannot open file.');
  41.   end;
  42. end;
  43.  
  44. procedure TForm1.FormCreate(Sender: TObject);
  45. begin
  46.   btnBackgroundColorChanged(Self);
  47. end;
  48.  
  49. procedure TForm1.btnBackgroundColorChanged(Sender: TObject);
  50. begin
  51.   Form1.Color := btnBackground.ButtonColor;
  52. end;
  53.  
  54. end.

 

TinyPortal © 2005-2018