Thema: Delphi Pixelmanipulation

Einzelnen Beitrag anzeigen

Phantom1

Registriert seit: 20. Jun 2003
282 Beiträge
 
Delphi 10.4 Sydney
 
#11

Re: Pixelmanipulation

  Alt 18. Sep 2005, 08:44
Zitat von Gothicware:
Delphi-Quellcode:
procedure _SemiOpaque(src:Tbitmap; Color:TColor);
var x,y:Integer;
    p:PInteger;
begin
  src.PixelFormat:=pf32bit;
  p:= src.Scanline[Pred(src.Height)];
  for y:=1 to src.Height do
  for x:=1 to src.Width do
    begin
      if ((x+0 mod 2) = 0) and ((y mod 2) = 0) then p^:= Color;
      if ((x+1 mod 2) = 0) and ((y mod 2) <> 0) then p^:= Color;
      Inc(p);
    end;
end;
Du weißt aber schon das die Bedingung (x+0 mod 2)=0 immer False ergibt, wenn x>0? Denn das Mod bindet mehr als das + zeichen.

Hier mal eine Variante von mir, ist dank Scanline auch recht schnell:
Delphi-Quellcode:
// Alpha 127 ist Halbtransparent
procedure TAnimation.DrawAlpha(Src, Dest: TBitmap; x, y: Integer; Alpha: Byte);
var
  s, d: PRGBQuad;
  Rect: TRect;
  x1, y1: Integer;
begin
  src.PixelFormat:=pf32bit;
  dest.PixelFormat:=pf32bit;
  if (x>=Dest.Width) or (x+Pred(Src.Width)<0) or
     (y>=Dest.Height) or (y+Pred(Src.Height)<0) then exit;
  with Rect do begin
    Left:=Max(x, 0);
    Top:=Max(y, 0);
    Right:=Min(x+Pred(Src.Width), Pred(Dest.Width));
    Bottom:=Min(y+Pred(Src.Height), Pred(Dest.Height));
  end;
  for y1:=Rect.Top to Rect.Bottom do begin
    d:=Dest.ScanLine[y1]; Inc(d, Rect.Left);
    s:=Src.ScanLine[y1-y]; Inc(s, Rect.Left-x);
    for x1:=Rect.Left to Rect.Right do begin
      d^.rgbRed:=(d^.rgbRed * Alpha + s^.rgbRed * not Alpha) shr 8;
      d^.rgbGreen:=(d^.rgbGreen * Alpha + s^.rgbGreen * not Alpha) shr 8;
      d^.rgbBlue:=(d^.rgbBlue * Alpha + s^.rgbBlue * not Alpha) shr 8;
      Inc(s);
      Inc(d);
    end;
  end;
end;
  Mit Zitat antworten Zitat