![]() |
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:
sie funktioniert aber nicht. meine theoretischen überlegungen sind also offenbar falsch....
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; was muss ich also anders machen? |
Re: Denkproblem: Skalierungsfaktor
Müsste es nicht
Delphi-Quellcode:
heißen ? :gruebel:
if horig>worig then // height bigger than width -> it will be scaled to width!
result:=hmax / horig else result := wmax / worig; |
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: ![]() |
Re: Denkproblem: Skalierungsfaktor
so, das hier schient zu funktionieren:
Delphi-Quellcode:
das problem ist allerdings die skalierungsfunktion.....
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; |
Re: Denkproblem: Skalierungsfaktor
Hallo Lukas,
ich verwende diesen Code, um Thumbnails fuer mein Fotoalbum einzupassen:
Code:
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.
$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; } } Greetz alcaeus |
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; |
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.....
|
Re: Denkproblem: Skalierungsfaktor
Muss es unbedingt kubisch sein? Ansonsten:
![]() |
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. |
Re: Denkproblem: Skalierungsfaktor
Schau dir dazu mal TBitmap.StretchFilter in Tateinheit mit TBitmap.Draw{To} an.
Die G32 kann folgende Interpolationen:
edit: ne richtige Liste is doch schöner :stupid: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:31 Uhr. |
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