1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
unit SPL;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, jpeg;
type
TPercent = 0..100;
TSplform = class(TForm)
Splashimg: TImage;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure WMEraseBkgnd(var msg: TWMErasebkgnd); message WM_ERASEBKGND;
private
procedure Afterfade;
{ Private declarations }
public
{ Public declarations }
procedure DoFade(Duree: integer);
procedure Wait(Duree: integer);
end;
var
Splform: TSplform;
scrbmp: TBitmap;
mixbmp: TBitmap;
procedure DrawTransparent(dstBitmap, srcBitmap: TBitmap; Transparency: TPercent);
procedure GetScreenBitmap(r: TRect; var bitmap: TBitmap);
implementation
uses Unit1;
procedure DrawTransparent(dstBitmap, srcBitmap: TBitmap; Transparency: TPercent);
const
MaxPixelCount = 32768;
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..MaxPixelCount] of TRGBTriple;
var
dstRow, srcRow: PRGBTripleArray;
x, y: Integer;
begin
dstBitmap.PixelFormat := pf24bit;
srcBitmap.PixelFormat := pf24bit;
for y := 0 to srcBitmap.Height-1 do
begin
srcRow := srcBitmap.ScanLine[y];
dstRow := dstBitmap.ScanLine[y];
for x := 0 to srcBitmap.Width-1 do
begin
dstRow[x].rgbtRed := ((100-Transparency) * dstRow[X].rgbtRed) div 100 +
(Transparency * srcRow[X].rgbtRed) div 100;
dstRow[x].rgbtGreen := ((100-Transparency) * dstRow[X].rgbtGreen) div 100 +
(Transparency * srcRow[X].rgbtGreen) div 100;
dstRow[x].rgbtBlue := ((100-Transparency) * dstRow[X].rgbtBlue) div 100 +
(Transparency * srcRow[X].rgbtBlue) div 100;
end;
end;
end;
procedure GetScreenBitmap(r: TRect; var bitmap: TBitmap);
var DC: HDC;
begin
Bitmap.Width := r.Right;
Bitmap.Height := r.Bottom;
DC := GetDC(0);
try
with Bitmap do
BitBlt(Canvas.Handle, 0, 0,
Width, Height, DC, r.Left, r.Top, SrcCopy);
finally
ReleaseDC(0, DC);
end;
end;
{$R *.dfm}
procedure TSplform.FormCreate(Sender: TObject);
begin
Splashimg.Visible := false;
end;
procedure TSplform.FormClose(Sender: TObject; var Action: TCloseAction);
begin
scrbmp.Free;
mixbmp.Free;
end;
procedure TSplform.FormShow(Sender: TObject);
begin
with self do begin
Splashimg.Width := Splashimg.Picture.Width;
Splashimg.Height := Splashimg.Picture.Height;
Width := Splashimg.Width;
Height := Splashimg.Height;
Left := round((Screen.Width) / 2 - (Width / 2));
Top := round((Screen.Height) / 2 - (Height / 2));
self.FormStyle := fsStayOnTop;
end;
end;
procedure TSplform.WMEraseBkgnd(var msg: TWMErasebkgnd);
begin
msg.Result := integer(false);
end;
procedure TSplform.DoFade(Duree: integer);
var
trans, delay: TPercent;
i: integer;
begin
scrbmp := TBitmap.Create;
mixbmp := TBitmap.Create;
mixbmp.Assign(Splashimg.Picture.Bitmap);
getscreenbitmap(rect(Left, Top, Width, Height), scrbmp);
try
delay := 0;
for i := 1 to duree do begin
trans := (i * 100) div duree;
if trans <> delay then begin
Splashimg.Picture.Assign(mixbmp);
drawtransparent(Splashimg.Picture.Bitmap, scrbmp, (100-trans));
if not SplashImg.Visible then
Splashimg.Visible := true;
end;
delay := trans;
application.ProcessMessages;
end;
finally
mixbmp.Free;
scrbmp.Free;
Afterfade;
end;
end;
procedure TSplform.Afterfade;
begin
wait(200);
end;
procedure TSplform.Wait(Duree: integer);
var
i: integer;
begin
for i := 1 to duree do begin
application.ProcessMessages;
sleep(1);
end;
end;
end. |
Partager