Announcement

Collapse
No announcement yet.

Bitmap's als Formular

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bitmap's als Formular

    Hi, wer kann mir sagen wie ich die Form eines Fensters durch ein Bitmap bestimmen kann. In der PC Magazin 2/2000 fand ich hierfür ein geradezu perfektes Beispiel (mit Transparent Effekten usw.), doch leider war es in C++ geschrieben. Und mangels ausreichender C++ Kenntnisse konnte ich es nicht Komplet in Delphi übersetzen.

  • #2
    Lade dir aus dem Internet das Freeware-Programm "Odd Form Assistant" herunter (ca 300kB):<br>
    http://www.informatics.no/subindex.htm
    <p>
    Die Software verwandelt ein Bitmap-Bild in Delphi-Code und erstellt transparente Forms.

    <p>
    Gruß,

    Bernhar

    Comment


    • #3
      hey, <br>
      danke für den Tip und die Seite sieht auch cool aus

      Comment


      • #4
        Hi

        <pre>
        function BitmapToRGN(B: TBitmap): hRGN;
        var
        X,Y,C,L,S: Integer;
        T: hRGN;
        P: PInteger;
        begin
        B.PixelFormat := pf24Bit;
        C := PInteger(B.ScanLine[B.Height-1])^ shr 8;
        Result := CreateRectRgn(0, 0, B.Width-1, B.Height-1);
        for Y := B.Height-1 downto 0 do
        begin
        P := B.ScanLine[Y];
        S := -1;
        for X := 0 to B.Width -1 do
        begin
        L := P^ shr 8;
        if (L = C) and (S = -1) then S := X else
        if (L <> C) and (S <> -1) then
        begin
        T := CreateRectRgn(S, Y, X, Y+1);
        CombineRgn(Result, Result, T, RGN_DIFF);
        DeleteObject(T);
        S := -1;
        end;
        Inc(PByte(P), 3);
        end;
        if S <> -1 then
        begin
        T := CreateRectRgn(S, Y, B.Width, Y+1);
        CombineRgn(Result, Result, T, RGN_DIFF);
        DeleteObject(T);
        end;
        end;
        end;
        </pre>

        Obiger Code konvertiert eine beliebige Bitmap in eine Region.
        Diese Region wird mit SetWindowRgn(FensterHandle, region, true) einem Fenster (Form) zugeordnet.

        Eine schnellere Routine würde die Bitmap in eine Monochrome (Zweifarbige) Bitmap umwandeln, und kann dann 8 Pixel in einem Rutsch auswerten. Leider finde ich meinen Code derzeit nicht wieder :-)

        Gruß Hage

        Comment


        • #5
          Hi

          hab's gefunden. Folgende Funktion erstellt aus einem beliebigen TPicture (also Bitmap, Icon, Metafile etc) auf schnelle Art die erforderliche Region.

          <pre>
          function PictureToRGN(Picture: TPicture): hRgn;
          var
          B: TBitmap;
          C: Byte;
          R: hRgn;
          P: PByte;
          S,E,Y: Integer;
          begin
          B := TBitmap.Create;
          try
          B.HandleType := bmDIB;
          B.PixelFormat := pf24Bit;
          B.Width := Picture.Width;
          B.Height := Picture.Height;
          B.Canvas.Draw(0, 0, Picture.Graphic);
          B.Mask(B.TransparentColor);
          B.PixelFormat := pf8Bit;
          C := PByte(B.Scanline[0])^;
          Result := CreateRectRgn(0, 0, B.Width, B.Height);
          for Y := B.Height-1 downto 0 do
          begin
          P := B.ScanLine[Y];
          S := 0;
          E := 0;
          repeat
          while (P^ = C) and (E < B.Width) do
          begin
          Inc(P);
          Inc(E);
          end;
          R := CreateRectRgn(S, Y, E, Y+1);
          try
          CombineRgn(Result, Result, R, RGN_DIFF);
          finally
          DeleteObject(R);
          end;
          while (P^ <> C) and (E < B.Width) do
          begin
          Inc(P);
          Inc(E);
          end;
          S := E;
          until E >= B.Width;
          if S <> E then
          begin
          R := CreateRectRgn(S, Y, E, Y+1);
          try
          CombineRgn(Result, Result, R, RGN_DIFF);
          finally
          DeleteObject(R);
          end;
          end;
          end;
          finally
          B.Free;
          end;
          end;
          </pre>

          Gruß Hage

          Comment


          • #6
            Danke Hagen, genau das was ich gesucht habe

            Comment

            Working...
            X