인터넷 여기 저기 뒤져가며 간신히 아래와 같은 코드를 완성했습니다.
첨부된 이미지는 실행화면이구요.
폼위에 반투명 32Bit PNG이미지를 올려놓고 실행하면
폼은 보이지 않고 PNG이미지 아래로 데스크탑 화면이 보이는데요.
일단은 원하는데로 되었습니다.
그런데 문제는 이렇게 하면 이미지 위에 올려놓은 버튼이 숨어버립니다.
버튼 뿐이 아니고 이미지를 올려놓아도 위에 있는 이미지는 보이지가 않습니다.
비록 버튼이나 이미지가 보이지 않아도 그 위치를 클릭하면 반응은 하는데
버튼이나 이미지가 보이게 할 방법 없을까요?
고수님들의 답변 기다리겠습니다.
아래 샘플입니다.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, GraphicEx;
type
TForm1 = class(TForm)
Image1: TImage;
procedure PremultiplyBitmap(Bitmap: TBitmap);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
GdipApi, GdipObj, ActiveX;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
BlendFunction: TBlendFunction;
BitmapPos: TPoint;
BitmapSize: TSize;
exStyle: DWORD;
Ticks: DWORD;
begin
// Enable window layering
exStyle := GetWindowLongA(Form1.Handle, GWL_EXSTYLE);
if (exStyle and WS_EX_LAYERED = 0) then
SetWindowLong(Form1.Handle, GWL_EXSTYLE, exStyle or WS_EX_LAYERED);
try
ASSERT(Image1.Picture.Bitmap.PixelFormat = pf32bit, 'Wrong bitmap format - must be 32 bits/pixel');
// PremultiplyBitmap(Image1.Picture.Bitmap);
// Resize form to fit bitmap
Form1.ClientWidth := Image1.Picture.Bitmap.Width;
Form1.ClientHeight := Image1.Picture.Bitmap.Height;
// Position bitmap on form
BitmapPos := Point(0, 0);
BitmapSize.cx := Image1.Picture.Bitmap.Width;
BitmapSize.cy := Image1.Picture.Bitmap.Height;
// Setup alpha blending parameters
BlendFunction.BlendOp := AC_SRC_OVER;
BlendFunction.BlendFlags := 0;
BlendFunction.SourceConstantAlpha := 0;
BlendFunction.AlphaFormat := AC_SRC_ALPHA;
Form1.Show;
// ... and action!
Ticks := 0;
while (BlendFunction.SourceConstantAlpha < 255) do
begin
while (Ticks = GetTickCount) do
Sleep(10); // Don't fade too fast
inc(BlendFunction.SourceConstantAlpha, (255-BlendFunction.SourceConstantAlpha) div 32+1); // Fade in
UpdateLayeredWindow(Form1.Handle, 0, nil, @BitmapSize, Image1.Picture.Bitmap.Canvas.Handle,
@BitmapPos, 0, @BlendFunction, ULW_ALPHA);
end;
finally
end;
end;
procedure TForm1.PremultiplyBitmap(Bitmap: TBitmap);
var
Row, Col: integer;
p: PRGBQuad;
PreMult: array[byte, byte] of byte;
begin
// precalculate all possible values of a*b
for Row := 0 to 255 do
for Col := Row to 255 do
begin
PreMult[Row, Col] := Row*Col div 255;
if (Row <> Col) then
PreMult[Col, Row] := PreMult[Row, Col]; // a*b = b*a
end;
for Row := 0 to Bitmap.Height-1 do
begin
Col := Bitmap.Width;
p := Bitmap.ScanLine[Row];
while (Col > 0) do
begin
p.rgbBlue := PreMult[p.rgbReserved, p.rgbBlue];
p.rgbGreen := PreMult[p.rgbReserved, p.rgbGreen];
p.rgbRed := PreMult[p.rgbReserved, p.rgbRed];
inc(p);
dec(Col);
end;
end;
end;
end.
|