Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#8

AW: Flip verändert die Farbe

  Alt 30. Dez 2017, 19:33
@Zacherl Thanks!

Es ist so wie du sagst.
Zitat:
Sonst werden transparente Pixel natürlich mit der angegebenen Hintergrundfarbe verrechnet.
Ich muss die Transparente Farbe vorher entfernen.
Das war aber nicht das einzige, zusätzlich bricht mir 'GdipCreateHBITMAPFromBitmap' den Hals..LOL

Habe es jetzt so verändert und es läuft zu meiner Zufriedenheit.
Ist kommentiert. (Wenn auch ein bisschen viel)

So macht man aus 16 Zeilen code mal eben 70!

Delphi-Quellcode:
        if (ObjItem.Flipmode <> 0) then
        begin
          if Flip then
          begin
            Flip := False;
            if ObjItem.Flipmode = GD_Reverse then
            begin
              Item := gItemFromID(ObjItem.ID);
              SelectObject(hDCsrce, ObjItem.Bitmap);
              // Create Image from DC using GdipCreateBitmapFromScan0
              Img := gBitmapToImage(hDCsrce);
              // Flip Image RotateNoneFlipX
              GdipImageRotateFlip(Img, 4);
              // Delete Old HBitmap
              DeleteObject(g_Obj[Item].Bitmap);
              // Get ImageSize
              GDIP_GetImageSize(Img, ImgW, ImgH);
              // CreateCompatibleDC from Source
              ImgHDC := CreateCompatibleDC(hDCsrce);
              // Create Memory Bitmap with 32 Bit support
              hbmpReturn := gCreateDIBSection(hDCsrce, ImgW, ImgH);
              // Select Memory Bitmap from DC
              SelectObject(ImgHDC, hbmpReturn);
              // Delete Old Source DC
              DeleteDC(hDCsrce);

              if (GdipCreateFromHDC(ImgHDC, Graphics) = OK) then
              begin
                // Draw image
                GdipDrawImageRect(Graphics, Img, 0, 0, ImgW, ImgH);
                // Set the new HBitmap
                g_Obj[Item].Bitmap := hbmpReturn;
                // Get Bitmap Object
                GetObject(hbmpReturn, sizeof(bm), @bm);
                pBits := bm.bmBits;
                // Remove Transparent Color Black $00000000
                for p := 0 to (bm.bmWidth * bm.bmHeight) do
                begin
                  ColorIs := RGB(pBits[2], pBits[1], pBits[0]);
                  if (ColorIs = $00000000) then
                  begin
                      pBits[3] := 0;
                      pBits[2] := 255;
                      pBits[1] := 0;
                      pBits[0] := 255;
                  end
                  else if (ColorIs = 0) then
                  begin
                      if (pBits[3] > 0) then
                        pBits[0] := 1;
                  end
                  else // Alpha channel for PNG image
                  begin
                      AlphaCoef := (255 shl 8) div pBits[3];
                      pBits[2] := ((pBits[2] * AlphaCoef) shr 8);
                      pBits[1] := ((pBits[1] * AlphaCoef) shr 8);
                      pBits[0] := ((pBits[0] * AlphaCoef) shr 8);
                  end;
                  pBits := pBits + 4;
                end;
              end;
              // Cleanup
              GdipDeleteGraphics(Graphics);
              // Set new Source DC
              hDCsrce := ImgHDC;
              // Delete old
              DeleteDC(ImgHDC);
              // Dispose Image
              if Img <> 0 then
                GdipCheck(GdipDisposeImage(Img));
            end;
          end;
        end;
Hat sich erledigt..

gruss
  Mit Zitat antworten Zitat