Skip to content

Commit

Permalink
transparent bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
RetroNick2020 committed Oct 24, 2024
1 parent 877fec0 commit bd6ca62
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 0 deletions.
80 changes: 80 additions & 0 deletions lazarus/Transparent Bitmap/project1.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<Title Value="project1"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes>
<Item Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="LCL"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="project1"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>
25 changes: 25 additions & 0 deletions lazarus/Transparent Bitmap/project1.lpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
program project1;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
{$IFDEF HASAMIGA}
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, unit1
{ you can add units after this };

{$R *.res}

begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

10 changes: 10 additions & 0 deletions lazarus/Transparent Bitmap/unit1.lfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object Form1: TForm1
Left = 165
Height = 478
Top = 385
Width = 639
Caption = 'Form1'
OnCreate = FormCreate
OnPaint = FormPaint
LCLVersion = '3.4.0.0'
end
81 changes: 81 additions & 0 deletions lazarus/Transparent Bitmap/unit1.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs;

type

{ TForm1 }

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private

public
BitMap1,BitMap2 : TBitMap;
end;

var
Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure RenderGrid(Canvas: TCanvas; Height, Width: Integer;
Size: Integer; Color1, Color2: TColor);
var
y: Integer;
x: Integer;
begin
for y := 0 to Height div Size do
for x := 0 to Width div Size do
begin
if Odd(x) xor Odd(y) then
Canvas.Brush.Color := Color1
else
Canvas.Brush.Color := Color2;
Canvas.FillRect(Rect(x*Size, y*Size, (x+1)*Size, (y+1)*Size));
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
BitMap1:=TBitmap.Create;
BitMap2:=TBitmap.Create;

BitMap1.SetSize(400,400);
BitMap2.SetSize(400,400);


BitMap1.PixelFormat:=pf24bit;
RenderGrid(BitMap1.Canvas,400,400,40,clWhite,clGray);

BitMap2.PixelFormat:=pf24bit;
BitMap2.TransparentColor:=clBlue;
BitMap2.TransparentMode:=tmFixed;
BitMap2.Transparent:=true;

BitMap2.canvas.Brush.Color:=clBlue;
BitMap2.Canvas.Rectangle(0,0,400,400);

BitMap2.canvas.Brush.Color:=clRed;
BitMap2.Canvas.Rectangle(10,10,80,80);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
// RenderGrid(canvas,400,400,40,clWhite,clGray);
canvas.Draw(0,0,BitMap1);
canvas.Draw(0,0,BitMap2);
end;

end.

0 comments on commit bd6ca62

Please sign in to comment.