Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox laden (https://www.delphipraxis.net/141345-%5Bgeloest%5D-bilder-bitmaps-transparent-eine-paintbox-laden.html)

delphi-n 7. Okt 2009 13:49


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

Ich hab ein Programm, bei dem ich die images aus einer imagelist TRANSPARENT auf eine Paintbox zeichnen will.

Leider klappt das nicht. (das transparente)

Ich hab das Programm mal gezippt, ihr könnts euch ja mal anschauen.

Vielen Dank für eure Hilfe :)



(ich hab den Anhang gelöscht, da man dort eh ncht viel sieht (das Problem ist ja auch gelößt), und weils den Server schont)

Sherlock 7. Okt 2009 14:08

Re: transparenz klappt nicht
 
Och, weisst Du, ein Bild hätte es auch getan. Ich denke mal Du hast vielleicht nicht die korrekte TransparentColor definiert?

Sherlock

Razor 7. Okt 2009 14:16

Re: transparenz klappt nicht
 
Delphi-Quellcode:
Form2.transparentcolorvalue:=clWhite;
Form2.transparentcolor:=true;

Sherlock 7. Okt 2009 14:22

Re: transparenz klappt nicht
 
Nah, that would be to easy. He's drawing the images from the ImageList into a PaintBox. There're no options for transparent in a PaintBox. The ImageList has something with masks, but I don't quit understand the use. :gruebel:

Sherlock

Razor 7. Okt 2009 14:25

Re: transparenz klappt nicht
 
Are you able to use PNG's?If so then use delphi's PNG Image control(Timage).But its only avaliable in D2009 or D2007 too.

DeddyH 7. Okt 2009 14:42

Re: transparenz klappt nicht
 
PNG is not natively supported in Delphi 2007. But maybe this could help: http://docs.embarcadero.com/products...AddMasked.html

delphi-n 7. Okt 2009 18:23

Re: transparenz klappt nicht
 
@deddy H:

wie soll das gehen? Ich check den Linkinhalt nicht :cry:

delphi-n 7. Okt 2009 20:54

Re: transparenz klappt nicht
 
Hier ist die Lösung:

man muss das Bitmap in ein Image laden. Das Image kann man ja transparent machen (unter eigenschaften)

dann läd man das Image so in die PaintBox:


Delphi-Quellcode:
  PaintBox1.Canvas.Draw(0, 50, Image1.Picture.Graphic);
    PaintBox1.Canvas.Draw(0, 34, Image1.Picture.Graphic);
Nur so als Beispiel.

Matze 8. Okt 2009 17:00

Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la
 
Das sieht mir aber sehr schlampig aus, wenn man da ein TImage mitschleifen muss, womöglich noch unsichtbar (schlimmer kann man die VCL meiner Meinung nach kaum einsetzen).
Vielleicht geht es auch nur mit einem TPicture. Probiert habe ich es nicht und super schön ist das wohl auch nicht.

Aktuell wird das den Weg wohl nicht in die CL finden (du hast es ja dafür vorgeschlagen). ;) Es geht sicher schöner (irgendwie :gruebel: ).

SirThornberry 8. Okt 2009 17:06

Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la
 
@Matze: Es geht auch unter Verwendung von TPicture. TImage macht auch nix anderes als TPicture zur Datenhaltung zu verwenden.
Die aufgezeigte Variante halte ich auch für fragwürdig. Wozu ein TImage nutzen wenn man davon nur das TPicture verwendet? Das ist als würde ich den ganzen Schrank mit zum Essen nehmen obwohl ich nur das Besteck daraus benötige.

delphi-n 8. Okt 2009 17:30

Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la
 
es funktioniert, und das ist (für mich) die Hauptsache! :thumb:

Matze 8. Okt 2009 18:10

Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la
 
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. :lol:

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:
Delphi-Quellcode:
DrawTransparent(ImageList1, 0, PaintBox1);
Das ist mehr zum Spaß und bei großen Bilder vermutlich nicht sehr schnell.

Grüße, Matze


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:51 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