Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

Farbe wird verändert

  Alt 8. Mai 2017, 07:09
Ich verwende diese Funktion um Bitmaps Transparent abzuspeichern.

Das Problem ist nur das diese anscheinend nicht korrekt arbeitet.
Was könnte da falsch sein. ?

oder aber ich initialisiere das TBitmap falsch.

zum vergleich "1" das dunkle ist von dieser Funktion das andere Original.
Delphi-Quellcode:
procedure TSkinEngine.SaveBitmapToFile(ImgFile: WideString; hbmp: HBITMAP);
var
  png: TPNGImage;
  ext : string;
  Bitmap: TBitmap;
begin
  ext := ExtractFileExt(ImgFile) ;
  if SameText(ext, '.png') then
  begin
    Bitmap := TBitmap.Create;
    Bitmap.Handle := hbmp;
    Bitmap.PixelFormat := pf32bit;
    Png := PNG4TransparentBitMap(Bitmap);
    try
      png.SaveToFile(ImgFile);
    finally
      png.Free;
      Bitmap.Free;
    end;
  end;
end;
Eine andere Fehlerquelle könnte auch diese sein.

Delphi-Quellcode:
procedure SetupAlphaChannel(DC: HDC);
var
  bm: BITMAP;
  P: integer;
  Alpha: Byte;
  pBits: PRGBQuad;
begin

  FillChar(bm, sizeof(bm), 0);

  GetObject(GetCurrentObject(DC, OBJ_BITMAP), sizeof(bm), @bm);
  pBits := bm.bmBits;
  for P := (bm.bmWidth * bm.bmHeight) downto 1 do
  begin
    Alpha := SKAERO_Rgb2Gray(RGB(pBits.rgbRed, pBits.rgbGreen, pBits.rgbBlue)) and $000000FF;
    if (Alpha = 0) and (pBits.rgbReserved = 0) then
      pBits.rgbReserved := 0
    else if (pBits.rgbReserved = 0) then
      pBits.rgbReserved := 255;

    inc(pBits);
  end;
end;
Delphi-Quellcode:
function TSkinEngine.Rgb2Gray(RGBValue: COLORREF): COLORREF;
asm
  XOR ESI, ESI
  XOR EDX, EDX
  MOV ECX, RGBValue

  // Red
  MOV EAX, 19595
  MOV DL, CL
  MUL EDX
  ADD ESI, EAX

  // Green
  MOV EAX, 38470
  SHR ECX, 8
  MOV DL, CL
  MUL EDX
  ADD ESI, EAX

  // Blue
  MOV EAX, 7471
  SHR ECX, 8
  MOV DL, CL
  MUL EDX
  ADD ESI, EAX

  SHR ESI, 16
  MOV EDX, ESI

  //' Put Gray Value to a DWORD (0GGG)
  XOR EAX, EAX
  OR AL, DL
  SHL EAX, 8
  OR AL, DL
  SHL EAX, 8
  OR AL, DL

  MOV RESULT, EAX
end;
sorry ASM ist ein rotes Tuch für mich.
Wenn ich jedoch SetupAlphaChannel deaktiviere habe ich das gleiche Resultat.
Entweder ist diese in Verbindung mit RGB2Gray fehlerhaft so das es keine rolle spielt ob ich diese deaktiviere
oder die obere(der Link) berechnet die Farben nicht korrekt.


gruss

Geändert von EWeiss (11. Jul 2019 um 15:47 Uhr)
  Mit Zitat antworten Zitat