- Delphiartiklar, tips, forum, länksamling - 

      

START | DELPHI | LÄNKARGÄSTBOK 




 Forum

Grundkurs
  »Introduktion
  »Snabbguide
  »Komponenter
  »Händelser
  »Strängar
  »Räkna med Delphi   »Egna typer
  »Selektion
  »Iteration
  »Menyer
  »Funktioner
  »Arraystrukturer

Tips & Tricks
  »Nya tips
  »Blandat
  »Databaser
  »Filer
  »Forms
  »Grafik
  »Internet
  »Komponenter
  »Matematik
  »Multimedia
  »Objekt/ActiveX
  »Skrivare
  »Strängar
  »System
  »Mest lästa tips

Artiklar
  »Delphi och ADO
  »Bygga en DLL
  »Skapa en enkel rapport
  »Hantera registret
  »Enheter, units
  »Klassen TCanvas
  »Använd LookUp Controls

 Nya tips
 Lägg till tips
 Delphilänkar
 Gästbok

 

Lägg till en AlphaBlend-effekt Kategori: Grafik
Inlagt: 2004-12-17
Läst: 1355
Inlagt av: Staffan Berg
Beskrivning
AlphaBlend har till uppgift att visa bilder som har transparenta eller halvtransparenta pixlar. Observera att det inte finns stöd för AlphaBlend i Windowsversioner tidigare än Windows 2000. 
Kod
const 
AC_SRC_ALPHA = $1; 
 
procedure DrawAlphaBlend (hWnd : HWND; hdcwnd : HDC); 
var 
  Ahdc : HDC;       // handle of the DC we will create 
  bf : BLENDFUNCTION;   // structure for alpha blending 
  Ahbitmap : HBITMAP;   // bitmap handle 
  bmi : BITMAPINFO;    // bitmap header 
  pvBits : pointer;    // pointer to DIB section 
  ulWindowWidth, 
  ulWindowHeight : ULONG; // window width/height 
  ulBitmapWidth, 
  ulBitmapHeight : ULONG; // bitmap width/height 
  rt : TRect;       // used for getting window dimensions 
begin 
  // get window dimensions 
  GetClientRect(hWnd, rt); 
 
  // calculate window width/height 
  ulWindowWidth := rt.right - rt.left; 
  ulWindowHeight := rt.bottom - rt.top; 
 
  // make sure we have at least some window size 
  if ((ulWindowWidth = 0 ) and (ulWindowHeight=0)) then 
    exit; 
 
  // divide the window into 3 horizontal areas 
  ulWindowHeight := trunc(ulWindowHeight / 3); 
 
  // create a DC for our bitmap -- the source DC for AlphaBlend 
  Ahdc := CreateCompatibleDC(hdcwnd); 
 
  // zero the memory for the bitmap info 
  ZeroMemory(@bmi, sizeof(BITMAPINFO)); 
 
  // setup bitmap info 
  bmi.bmiHeader.biSize := sizeof(BITMAPINFOHEADER); 
  bmi.bmiHeader.biWidth := trunc(ulWindowWidth - (ulWindowWidth/5)*2); 
  ulBitmapWidth := trunc(ulWindowWidth - (ulWindowWidth/5)*2); 
  bmi.bmiHeader.biHeight := trunc(ulWindowHeight - (ulWindowHeight/5)*2); 
  ulBitmapHeight := trunc(ulWindowHeight - (ulWindowHeight/5)*2); 
  bmi.bmiHeader.biPlanes := 1; 
  bmi.bmiHeader.biBitCount := 32;     // four 8-bit components 
  bmi.bmiHeader.biCompression := BI_RGB; 
  bmi.bmiHeader.biSizeImage := ulBitmapWidth * ulBitmapHeight * 4; 
 
  // create our DIB section and select the bitmap into the dc 
  Ahbitmap := CreateDIBSection(Ahdc, bmi, DIB_RGB_COLORS, pvBits, 0, 0); 
  SelectObject(Ahdc, Ahbitmap); 
 
  bf.BlendOp := AC_SRC_OVER; 
  bf.BlendFlags := 0; 
  bf.SourceConstantAlpha := $7f; // half of 0xff = 50% transparency 
  bf.AlphaFormat := 0;       // ignore source alpha channel 
 
  AlphaBlend(hdcwnd, trunc(ulWindowWidth/5), trunc(ulWindowHeight/5), 
          ulBitmapWidth, ulBitmapHeight, 
          Ahdc, 0, 0, ulBitmapWidth, ulBitmapHeight, bf); 
 
 
  bf.BlendOp := AC_SRC_OVER; 
  bf.BlendFlags := 0; 
  bf.AlphaFormat := AC_SRC_ALPHA; // use source alpha 
  bf.SourceConstantAlpha := $ff; // opaque (disable constant alpha) 
 
  AlphaBlend(hdcwnd, trunc(ulWindowWidth/5), 
   trunc(ulWindowHeight/5+ulWindowHeight), ulBitmapWidth, ulBitmapHeight,  
   Ahdc, 0, 0, ulBitmapWidth, ulBitmapHeight, bf); 
 
  bf.BlendOp := AC_SRC_OVER; 
  bf.BlendFlags := 0; 
  bf.AlphaFormat := 0; 
  bf.SourceConstantAlpha := $3A; 
 
  AlphaBlend(hdcwnd, trunc(ulWindowWidth/5), 
        trunc(ulWindowHeight/5+2*ulWindowHeight), ulBitmapWidth, 
        ulBitmapHeight, Ahdc, 0, 0, ulBitmapWidth, 
        ulBitmapHeight, bf); 
 
  // do cleanup 
  DeleteObject(Ahbitmap); 
  DeleteDC(Ahdc); 
 
end;  
 

 
 
© Copyright 2005 - Staffan Berg
- Alla rättigheter förbehålles -