Einzelnen Beitrag anzeigen

Muetze1
(Gast)

n/a Beiträge
 
#16

Re: Bild in eine Buttonkomponente??

  Alt 18. Feb 2008, 17:48
Delphi-Quellcode:
function CreateBitmapRegion(const ABitmap: TBitmap): HRGN;
var
  lTransparentColor: TRGBTriple;
  lX, lY, lStartX: Integer;
  lPixel: PRGBQuad;
  lExcluded: HRGN;
begin
  if assigned(ABitmap) then
  begin
    result := CreateRectRGN(0, 0, ABitmap.Width, ABitmap.Height);

    ABitmap.PixelFormat := pf32bit;

    lTransparentColor.rgbtRed := GetRValue(ColorToRGB(ABitmap.TransparentColor));
    lTransparentColor.rgbtGreen := GetGValue(ColorToRGB(ABitmap.TransparentColor));
    lTransparentColor.rgbtBlue := GetBValue(ColorToRGB(ABitmap.TransparentColor));

    for lY := 0 to pred(ABitmap.Height) do
    begin
      lPixel := ABitmap.Scanline[lY];

      lStartX := -1;

      for lX := 0 to pred(ABitmap.Width) do
      begin
        if (lPixel^.rgbRed = lTransparentColor.rgbtRed) and
           (lPixel^.rgbGreen = lTransparentColor.rgbtGreen) and
           (lPixel^.rgbBlue = lTransparentColor.rgbtBlue) then
        begin
          if lStartX = -1 then
            lStartX := lX;
        end
        else
        begin
          if lStartX > -1 then
          begin
            lExcluded := CreateRectRGN(lStartX, lY, lX, succ(lY));
            try
              CombineRGN(result, result, lExcluded, RGN_DIFF);
              lStartX := -1;
            finally
              DeleteObject(lExcluded);
            end;
          end;
        end;
        Inc(lPixel);
      end;

      if lStartX > -1 then
      begin
        lExcluded := CreateRectRGN(lStartX, lY, ABitmap.Width, succ(lY));
        try
          CombineRGN(result, result, lExcluded, RGN_DIFF);
        finally
          DeleteObject(lExcluded);
        end;
      end;
    end;
  end
  else
    result := 0;
end;
Liefert dir eine Region zu dem übergebenen Bild, wobei die Region alle Teile ausschliesst, welche die Transparenzfarbe des Bitmaps haben.

Ansonsten: MSDN-Library durchsuchenSetWindowRgn()
  Mit Zitat antworten Zitat