Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[14519] Re:자답 및 재질문입니다.
하두고 [hadugo] 3590 읽음    2012-12-10 14:34
인터넷 여기 저기 뒤져가며 간신히 아래와 같은 코드를 완성했습니다.
첨부된 이미지는 실행화면이구요.

폼위에 반투명 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.

+ -

관련 글 리스트
14517 이미지를 반투명하게 처리하고 싶은데요. 하두고 3323 2012/12/07
14519     Re:자답 및 재질문입니다. 하두고 3590 2012/12/10
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.