Rechenproblem

SCIPIO-AEMILIANUS

aka Dubdidadu
Ich hab im moment folgenden Code:
Code:
        CString buf;
        buf.Format(L"%i,%i",img.GetWidth(),img.GetHeight());
        MessageBox(buf,buf,0);
        buf.Format(L"%i,%i",outputSize.Width(),outputSize.Height());
        MessageBox(buf,buf,0);
        if((outputSize.Width()/outputSize.Height())<(img.GetWidth()/img.GetHeight())){
            height=outputSize.Height();
            width=(height/img.GetHeight()*img.GetWidth());
        }
        else{
            width=outputSize.Width();
            height=(width/img.GetWidth()*img.GetHeight());
        }
        buf.Format(L"%i,%i",width,height);
        MessageBox(buf,buf,0);

Die MessageBoxes hab ich zum überprüfen eingebaut.
Ich hab jetzt 2 verschiedene Bilder die ich verarbeite.
Beim ersten durchlauf siehts so aus:
800,600
980,772
980,600
Und bei dem zweiten Bild:
999,666
980,772
980,0

Warum berechnet der für height beim zweiten eine 0?

PS: Mir fällt grad auf, das die erste Rechnung auch falsch ist.
 
Zuletzt bearbeitet:
Code:
        double imgWidth=img.GetWidth()*1.0;
        double imgHeight=img.GetHeight()*1.0;
        double outWidth=outputSize.Width()*1.0;
        double outHeight=outputSize.Height()*1.0;
        if((outWidth/outHeight)>(imgWidth/imgHeight)){
            height=outHeight;
            width=round(height/imgHeight*imgWidth);
        }
        else{
            width=outWidth;
            height=round(width/imgWidth*imgHeight);
        }

4 Stunden rumprobiert und schlussendlich gelöst.
 
Zurück