Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Denkproblem: Skalierungsfaktor (https://www.delphipraxis.net/45914-denkproblem-skalierungsfaktor.html)

DGL-luke 14. Mai 2005 12:21


Denkproblem: Skalierungsfaktor
 
ich habe eine paintbox/ein image mit einer bestimmten breite und höhe. jetzt will ich in diese ein bitmap einfügen, das hineinpasst, aber nicht verzerrt ist.

ich hab da jetzt mal diese funktion geschrieben, die mir einen streckfaktor zurückliefern sollte:

Delphi-Quellcode:
function getfactor(horig,worig,hmax,wmax:integer):real;
begin
if horig>worig then // height bigger than width -> it will be scaled to width!
 result:=wmax / horig
else
 result := hmax / worig;

{
let's assume i have a bitmap with 250x300, which shall be scaled to a paintbox with
100x100. then the original height has to be scaled to 100, making a factor 100/300 = 0.3
}
end;
sie funktioniert aber nicht. meine theoretischen überlegungen sind also offenbar falsch....

was muss ich also anders machen?

jfheins 14. Mai 2005 12:28

Re: Denkproblem: Skalierungsfaktor
 
Müsste es nicht
Delphi-Quellcode:
if horig>worig then // height bigger than width -> it will be scaled to width! 
result:=hmax / horig
else
result := wmax / worig;
heißen ? :gruebel:

DGL-luke 14. Mai 2005 12:31

Re: Denkproblem: Skalierungsfaktor
 
keine ahnung :mrgreen:

aber ich teste es mal!

EDIT: funzt nicht aufs erste, ich hätte es aber gerne mit begründung, so dass ich es auch nachvollziehen kann.

EDIT2: hier mal ein bild:
http://luke.delphigl.com/img/scaling.gif

DGL-luke 14. Mai 2005 14:36

Re: Denkproblem: Skalierungsfaktor
 
so, das hier schient zu funktionieren:

Delphi-Quellcode:
function getfactor(horig,worig,hmax,wmax:integer):real;
var factor:real;
begin
//i have got the dimensions of the bitmap and the one
//of the canvas. so now i need the scale factor to get the
//bitmap into the canvas.
factor:= wmax/worig;

if horig * factor > hmax then
 factor := hmax/horig;

result:=factor;

//not optimal, but should do it for now

end;
das problem ist allerdings die skalierungsfunktion.....

alcaeus 14. Mai 2005 15:03

Re: Denkproblem: Skalierungsfaktor
 
Hallo Lukas,

ich verwende diesen Code, um Thumbnails fuer mein Fotoalbum einzupassen:
Code:
$pic_size = @getimagesize(ALBUM_UPLOAD_PATH . $pic_filename);
$pic_width = $pic_size[0];
$pic_height = $pic_size[1];
if( ($pic_width > $max_width) or ($pic_height > $max_height) )
{
   // ----------------------------
   // Resize it
   // ----------------------------

   $thumbnail_temp_width = $max_width;
   $thumbnail_temp_height = $max_width * ($pic_height/$pic_width);
   if ($thumbnail_temp_height > $max_height)
   {
      $thumbnail_height = $max_height;
      $thumbnail_width = $max_height * ($pic_width/$pic_height);
   }
   else
   {
      $thumbnail_width = $thumbnail_temp_width;
      $thumbnail_height = $thumbnail_temp_height;
   }
}
Ist zwar in PHP, aber das Prinzip sollte klar werden: ich passe es einfach auf die Breite ein. Wenn es nachher zu gross ist, passe ich es eben auf die Hoehe ein, sonst lasse ich es so.

Greetz
alcaeus

Basilikum 14. Mai 2005 15:04

Re: Denkproblem: Skalierungsfaktor
 
Delphi-Quellcode:
function getfactor(horig,worig,hmax,wmax:integer):real;
begin
  result:=min(hmax / horig,wmax / worig); // min: Unit Math

  // ev. Vergrösserung verhindern:
  if (result > 1) then result:=1;
end;

DGL-luke 14. Mai 2005 15:09

Re: Denkproblem: Skalierungsfaktor
 
jo, danke, jetzt muss ich aber erstmal die skalierungsfunkltion selbst hinkriegen. es sei denn, ihr wisst auf anhieb, wo ich kubische interpolation als c&p bekomm.....

dizzy 14. Mai 2005 15:30

Re: Denkproblem: Skalierungsfaktor
 
Muss es unbedingt kubisch sein? Ansonsten: Graphics 32 ;)

DGL-luke 14. Mai 2005 15:32

Re: Denkproblem: Skalierungsfaktor
 
die hab ich eh schon eingebunden. für png-images... mal sehen, was es da zum skalieren gibt.

sollte halt n bisschen besser ausschauen als stretchdraw.

dizzy 14. Mai 2005 16:19

Re: Denkproblem: Skalierungsfaktor
 
Schau dir dazu mal TBitmap.StretchFilter in Tateinheit mit TBitmap.Draw{To} an.

Die G32 kann folgende Interpolationen:
  • sfNearest (wie Stretchdraw)
  • sfLinear
  • sfCosine
  • sfSpline
  • sfLanczos (mein Favorit, aber der langsamste)
  • sfMitchell (fast so gut wie Lanczos, etwas schneller und beim Vergrößern u.U. besser geeignet. Beim Verkleinern etwas unschärfer als Lanczos)


edit: ne richtige Liste is doch schöner :stupid:


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:31 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz