Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   BMP Resize suche guten Algorithmus (https://www.delphipraxis.net/157776-bmp-resize-suche-guten-algorithmus.html)

ATS3788 24. Jan 2011 19:10

BMP Resize suche guten Algorithmus
 
Hallo

Weiß jemand einen Link für einen guten Algorithmus
zum vergrößern verkleinern einer Bitmap.

Delphi-Quellcode:
function ResizeBitmap(_Bitmap : TBitmap; const maxWidth, maxHeight : integer) : boolean;
 var
   thumbnail : TBitmap;
   thumbRect : TRect;
 begin

   try
    thumbnail := TBitmap.Create;
     thumbRect.Left := 0;
     thumbRect.Top := 0;
      thumbnail.Assign(_Bitmap);

     //proportional resize
     if thumbnail.Width > thumbnail.Height then
     begin
       thumbRect.Right := maxWidth;
       thumbRect.Bottom := (maxWidth * thumbnail.Height) div thumbnail.Width;
     end
     else
     begin
       thumbRect.Bottom := maxHeight;
       thumbRect.Right := (maxHeight * thumbnail.Width) div thumbnail.Height;
     end;

     thumbnail.Canvas.StretchDraw(thumbRect, thumbnail) ;

//resize image
     thumbnail.Width := thumbRect.Right;
    thumbnail.Height := thumbRect.Bottom;

     //display in a TImage control
     Form4.Im.Picture.Assign(nil);
       thumbnail.SaveToFile('d:\zz.bmp');
    Form4.Im.Picture.Assign(thumbnail);
   finally
     thumbnail.Free;
   end;
 end;
Habe dies im Netz gefunden mit beschränkten
"Antialiasing" Ergebnis.

Aphton 24. Jan 2011 19:19

AW: BMP Resize suche guten Algorithmus
 
Ist ein guter Resizealgorithmus jener, der kein beschränktes Antialiasing hat?

Wie wärs wenn du das Bild selber vergrößerst und den Gaußschen Weichzeichneralgorithmus drüberwälzt?

Memnarch 24. Jan 2011 19:42

AW: BMP Resize suche guten Algorithmus
 
Und dann wäre noch die Frage zu klären: Performance? wichtig oder unwichtig?

MFG
Memnarch

Aphton 24. Jan 2011 19:46

AW: BMP Resize suche guten Algorithmus
 
Zitat:

Zitat von Memnarch (Beitrag 1076983)
Und dann wäre noch die Frage zu klären: Performance? wichtig oder unwichtig?

MFG
Memnarch

Da hat einer Erfahrung, gell? xD

jfheins 24. Jan 2011 19:48

AW: BMP Resize suche guten Algorithmus
 
Da nach "gut" und nicht nach "schnell" gefragt wurde: Bikubische Interpolation

Bummi 24. Jan 2011 20:28

AW: BMP Resize suche guten Algorithmus
 
Die besten Ergebnisse bei wenig Aufwand bekomme mit GDI+

benötigt drei units aus GDI+ http://www.progdigy.com/

Delphi-Quellcode:
unit ExGraphicUtils;
//2010 Thomas Wassermann www.explido-software.de

interface
uses Windows, Classes, Sysutils, Graphics,GDIPAPI,GDIPOBJ,PNGImage, StdCtrls, jpeg, ActiveX;

Type TGPImageWrapper=Class(TObject)
       private
       FImage: TGPImage;
       FStream: TMemoryStream;
       public
       Constructor Create(AGraphic:TGraphic);
       Destructor Destroy;override;
       Public
       Property Image:TGPImage read FImage;
End;

procedure SetCanvasZoomFactor(Canvas: TCanvas; AZoomFactor: Integer);
Procedure SetCanvasZoomAndRotation(ACanvas:TCanvas;Zoom:Double;Angle:Double;CenterpointX,CenterpointY:Double);
Procedure ScaleImage(source:String;dest:TCanvas;DestRect:Trect;Center:Boolean=true);overload;
Procedure ScaleImage(source:TGraphic;dest:TCanvas;DestRect:Trect;Center:Boolean=true);overload;
function CreateGraphicFromFile(const Filename: string): TGraphic;
procedure MirrorBitmap(Bmp, MBmp: TBitmap;Horizonal:Boolean=true);
Function FileNameIsImage(Const fn:String):Boolean;
implementation

/// SNIPP


Procedure ScaleImage(source:String;dest:TCanvas;DestRect:Trect;Center:Boolean=true);overload;
var
  graphics : TGPGraphics;
  image: TGPImage;
  width, height: Integer;
  faktor:Double;
  X, Y:Double;
begin
  image:= TGPImage.Create(source);
  try
  width := image.GetWidth;
  height := image.GetHeight;
  if ((DestRect.Right - DestRect.Left) / width) < ((DestRect.Bottom -DestRect.Top)/Height) then faktor := (DestRect.Right - DestRect.Left) / width else faktor:= ((DestRect.Bottom -DestRect.Top)/Height);
  Faktor := ABS(Faktor);
  if Center then
      begin
        X := ((Destrect.Right - Destrect.Left) - faktor * width ) / 2;
        Y := ((Destrect.Bottom - Destrect.Top) - faktor * Height ) / 2;
      end
  else
      begin
        X := Destrect.Left;
        Y := Destrect.Top;

      end;
  graphics := TGPGraphics.Create(dest.Handle);
  try
    graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
    graphics.DrawImage( image, MakeRect(X, Y , faktor * width, faktor * height), 0, 0, width, height, UnitPixel);
  finally
    graphics.Free;
  end;
  finally
  image.Free;
  end;
end;

Procedure ScaleImage(source:TGraphic;dest:TCanvas;DestRect:Trect;Center:Boolean=true);overload;
// Das Bild graphics : TGPGraphics "lebt" nur so lange wie der Stream STR lebt
var
  graphics : TGPGraphics;
  imagewrapper: TGPImageWrapper;
  width, height: Integer;
  faktor:Double;

  X, Y:Double;
begin
  imagewrapper := TGPImageWrapper.Create(source);
  try
  width := imagewrapper.image.GetWidth;
  height := imagewrapper.image.GetHeight;
  if ((DestRect.Right - DestRect.Left) / width) < ((DestRect.Bottom -DestRect.Top)/Height) then faktor := (DestRect.Right - DestRect.Left) / width else faktor:= ((DestRect.Bottom -DestRect.Top)/Height);
  Faktor := ABS(Faktor);
  if Center then
      begin
        X := Destrect.Left + ((Destrect.Right - Destrect.Left) - faktor * width ) / 2;
        Y := Destrect.Top + ((Destrect.Bottom - Destrect.Top) - faktor * Height ) / 2;
      end
  else
      begin
        X := Destrect.Left;
        Y := Destrect.Top;

      end;
  graphics := TGPGraphics.Create(dest.Handle);
  try
    graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
    graphics.DrawImage( imagewrapper.image, MakeRect(X, Y , faktor * width, faktor * height), 0, 0, width, height, UnitPixel);
  finally
    graphics.Free;
  end;
  finally
  imagewrapper.Free;
  end;
end;

Memnarch 24. Jan 2011 23:22

AW: BMP Resize suche guten Algorithmus
 
@JHeins: Also ich möchte dich jetzt nicht in eine Philosophische diskussion über 'Gut' ziehen, aber ein Guter algorythmuss kan gut sein, weil er schnell ist, weil er performant ist, weil er wenig speicher verbaucht, weil er das optimum der 3 vorherigen kombiniert ;)

Aphton 24. Jan 2011 23:44

AW: BMP Resize suche guten Algorithmus
 
Zitat:

Zitat von Memnarch (Beitrag 1077062)
@JHeins: Also ich möchte dich jetzt nicht in eine Philosophische diskussion über 'Gut' ziehen, aber ein Guter algorythmuss kan gut sein, weil er schnell ist, weil er performant ist, weil er wenig speicher verbaucht, weil er das optimum der 3 vorherigen kombiniert ;)

Jup, so ist es. Wahrscheinlich falsche Wortwahl aber es wurde verstanden, was er gemeint hat...

ATS3788 25. Jan 2011 07:36

AW: BMP Resize suche guten Algorithmus
 
Danke für eure Antworten

Performance gute Frage

Nö die ist mir hier nicht wichtig

ATS3788 25. Jan 2011 07:57

AW: BMP Resize suche guten Algorithmus
 
Danke Bummi, GDI+ das sind ja total Mächtige Tool's für Grafik.
Ergänzung
Zitat:

Mit richtig guten Ergebnissen


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:03 Uhr.
Seite 1 von 2  1 2      

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