hallo
ich hab grad eine kleine zwischenaufgabe zu lösen und steh gerade an.
ich habe ein bild und muss es in der größe verändern.
nun muss ich ermitteln obs landscape ist oder nicht (breitbild)
dazu überprüfe ich obs breiter ist als es hoch ist...
jetzt muss ich noch die aspekt ratio einhalten (damits nicht verzerrt wird)
alles easy. ABER
so sollte das doch stimmen nur... kommt bei mir folgende ausgabe:
dachte mir ... kann doch nicht sein... darum eine kleine MAIN funktion zum testen...
ratet mal was hier rauskommt?
:bahnhof:
ich hab grad eine kleine zwischenaufgabe zu lösen und steh gerade an.
ich habe ein bild und muss es in der größe verändern.
nun muss ich ermitteln obs landscape ist oder nicht (breitbild)
dazu überprüfe ich obs breiter ist als es hoch ist...
jetzt muss ich noch die aspekt ratio einhalten (damits nicht verzerrt wird)
alles easy. ABER
Code:
imgWidth = image.getWidth();
imgHeight = image.getHeight();
isLandscape = imgWidth > imgHeight;
aspektRatio = new Double(imgWidth) / new Double(imgWidth);
newHeight = new Double(getSize().width / aspektRatio).intValue();
newWidth = new Double(getSize().height / aspektRatio).intValue();
System.out.println("imgWidth:"+imgWidth);
System.out.println("imgHeight:"+imgHeight);
System.out.println("aspektRatio:"+aspektRatio);
System.out.println("newWidth:"+newWidth);
System.out.println("newHeight:"+newHeight);
AR: 1.0
imgWidth:566
imgHeight:407
aspektRatio:1.0
newWidth:0
newHeight:0
dachte mir ... kann doch nicht sein... darum eine kleine MAIN funktion zum testen...
Code:
int width = 566;
int height = 407;
Double ar = new Double(width) / new Double(height);
System.out.println(ar);
int newHeight = new Double(800 / ar).intValue();
System.out.println("as width is scaled to 800, the new height is: "
+ newHeight);
und das ist eigentlich das, was ich mir auch oben erwartet hätte... kann im code nichts finden was mich auf das 1.0 schiebt...1.3906633906633907
as width is scaled to 800, the new height is: 575
:bahnhof: