Thema: Delphi Ein Bild Zerlegen

Einzelnen Beitrag anzeigen

Benutzerbild von SleepyMaster
SleepyMaster

Registriert seit: 18. Mai 2003
634 Beiträge
 
#7

Re: Ein Bild Zerlegen

  Alt 18. Dez 2005, 15:04
Ja, ich mittel die Farbwerte. Hier jetzt mal die optimierte Funktion von mir...

Delphi-Quellcode:
function DoResize(Bitmap: TBitmap; Width, Height: integer): TBitmap;
var
  SizeX, SizeY, X1, Y1, X2, Y2, I, J, PixelsInRect: integer;
  R, G, B: int64;
  Color: TColor;
  p1, p2 : pIntegerArray;
begin
  result := TBitmap.Create;

  result.PixelFormat := pf32Bit;
  Bitmap.PixelFormat := pf32Bit;

  SizeX := trunc(Bitmap.Width / Width);
  SizeY := trunc(Bitmap.Height / Height);

  result.Width := trunc(Bitmap.Width / SizeX);
  result.Height := trunc(Bitmap.Height / SizeY);

  PixelsInRect := (SizeX + 1) * (SizeY + 1);

  Y1 := 0;
  Y2 := 0;
  while Y1 <= (Bitmap.Height - SizeY) do
    begin
    p2 := result.ScanLine[Y2];
    x1 := 0;
    X2 := 0;
    while X1 <= (Bitmap.Width - SizeX) do
      begin
      r := 0;
      g := 0;
      b := 0;
      for i := 0 to SizeY do
        begin
        p1 := Bitmap.ScanLine[y1];
        for j := 0 to SizeX do
          begin
          b := b + (p1[x1] and $0000FF);
          g := g + ((p1[x1] and $00FF00) shr 8);
          r := r + ((p1[x1] and $FF0000) shr 16);
          end;
        end;
      p2[X2] := trunc(B / (PixelsInRect)) + (trunc(G / (PixelsInRect)) shl 8) + (trunc(R / (PixelsInRect)) shl 16);
      X1 := X1 + SizeX;
      X2 := X2 + 1;
      end;
    Y1 := Y1 + SizeY;
    Y2 := Y2 + 1;
    end;
end;
Edit1: Code nochmals optimiert
Edit2: und nochmal
Edit3: Fehler ausgebessert
  Mit Zitat antworten Zitat