AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Denkproblem: Skalierungsfaktor
Thema durchsuchen
Ansicht
Themen-Optionen

Denkproblem: Skalierungsfaktor

Ein Thema von DGL-luke · begonnen am 14. Mai 2005 · letzter Beitrag vom 14. Mai 2005
Antwort Antwort
Seite 1 von 2  1 2      
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#1

Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 12:21
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?
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von jfheins
jfheins

Registriert seit: 10. Jun 2004
Ort: Garching (TUM)
4.579 Beiträge
 
#2

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 12:28
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 ?
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#3

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 12:31
keine ahnung

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
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#4

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 14:36
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.....
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von alcaeus
alcaeus

Registriert seit: 11. Aug 2003
Ort: München
6.537 Beiträge
 
#5

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 15:03
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
Andreas B.
Die Mutter der Dummen ist immer schwanger.
Ein Portal für Informatik-Studenten: www.infler.de
  Mit Zitat antworten Zitat
Basilikum

Registriert seit: 9. Aug 2003
389 Beiträge
 
Delphi 7 Professional
 
#6

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 15:04
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;
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#7

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 15:09
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.....
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von dizzy
dizzy

Registriert seit: 26. Nov 2003
Ort: Lünen
1.932 Beiträge
 
Delphi 7 Enterprise
 
#8

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 15:30
Muss es unbedingt kubisch sein? Ansonsten: Graphics 32
Fabian K.
INSERT INTO HandVonFreundin SELECT * FROM Himmel
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#9

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 15:32
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.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von dizzy
dizzy

Registriert seit: 26. Nov 2003
Ort: Lünen
1.932 Beiträge
 
Delphi 7 Enterprise
 
#10

Re: Denkproblem: Skalierungsfaktor

  Alt 14. Mai 2005, 16:19
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
Fabian K.
INSERT INTO HandVonFreundin SELECT * FROM Himmel
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:26 Uhr.
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