AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox laden

[GELÖST]: Bilder/Bitmaps transparent in eine PaintBox laden

Ein Thema von delphi-n · begonnen am 7. Okt 2009 · letzter Beitrag vom 8. Okt 2009
Antwort Antwort
Seite 2 von 2     12
delphi-n

Registriert seit: 6. Sep 2009
88 Beiträge
 
#11

Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la

  Alt 8. Okt 2009, 17:30
es funktioniert, und das ist (für mich) die Hauptsache!
  Mit Zitat antworten Zitat
Benutzerbild von Matze
Matze
(Co-Admin)

Registriert seit: 7. Jul 2003
Ort: Schwabenländle
14.929 Beiträge
 
Turbo Delphi für Win32
 
#12

Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la

  Alt 8. Okt 2009, 18:10
Etwas langsam aufgrund des pixelweisen Zeichnens auf der PaintBox und Delphi-Referenz durchsuchenBitBlt geht da leider nicht, aber sonst geht der folgende Code bei mir.

Delphi-Quellcode:
procedure DrawTransparent(ImgList: TImageList; ImgLIndex: Integer; PaintBox: TPaintBox);
// some crazy declarations
type TRGB = packed record
  R, G, B: Byte;
end;

type TLine = array[0..0] of TRGB;

var
  MyBitmap: TBitmap;
  x, y: Integer;
  PLine: ^TLine;
  PixelColor, TranspColor: TColor;
begin
  MyBitmap := TBitmap.Create;
  try
    MyBitmap.PixelFormat := pf24bit;

    // get bitmap from the TImageList
    ImgList.GetBitmap(ImgLIndex, MyBitmap);

    // the transparant color is in the upper left corner
    TranspColor := MyBitmap.Canvas.Pixels[0, 0];

    // read pixels from the bitmap
    for y := 0 to MyBitmap.Height - 1 do
    begin
      for x := 0 to MyBitmap.Width - 1 - 1 do
      begin
        PLine := MyBitmap.ScanLine[y];

        // check if the color of the current pixel is TranspColor
        PixelColor := RGB(PLine[x].R, PLine[x].G, PLine[x].B);

        // draw pixels on the TPaintBox.Canvas
        if PixelColor <> TranspColor then
        begin
          PaintBox.Canvas.Pixels[x, y] := PixelColor;
        end;
      end;
    end;
  finally
    FreeAndNil(MyBitmap);
  end;
end;
Die Farbe des oberen linken Pixels wird als transparente Farbe genommen.

Aufruf:
DrawTransparent(ImageList1, 0, PaintBox1); Das ist mehr zum Spaß und bei großen Bilder vermutlich nicht sehr schnell.

Grüße, Matze
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz