c++ - aspect ratio of photo in preview pane where height is constant and only width varies -


i have problem when created preview handler image . problem when have photo on preview pane dont resize maintaining aspect ratio want write code photo resize maintaining aspect ratio of image. have keep in mind when resize image using algorithim should maintain aspect ratio , image should have possible maximum size in preview pane (i mean there shouldn't other algorithim have image preview of bigger size image obtained our algorithim maintained aspect ratio well).

we have keep in mind height of preview pane constant factor have deal changing width only(i mean according changing width have maintain aspect ratio both height , width of image). developing algorthim appreciated.

  • i'll define 2 ratios first.

    imageratio = widthofimage / heightofimage ,

    windowratio = widthofpreviewpane / heightofpreviewpane.

  • second, may try windows explorer again. when windowratio smaller imageratio , drag pane vertically, height of preview pane change.

    enter image description here

  • finally, may actualwidthofimage , actualheightofimage below:

    if (windowratio > imageratio) {     actualheightofimage = heightofpreviewpane;     actualwidthofimage = actualheightofimage * imageratio; } else {     actualwidthofimage = widthofpreviewpane;     actualheightofimage = actualwidthofimage / imageratio; } 

am understand problem correctly? i'd if got further questions.


Comments