Hi Guys,
I'm writing a program that must display images of any size to a
screen of dimensions 320x568.
I'm handling fixing the aspect ratio myself.
I have handled the cases where both image dimensions are smaller
than screen dimensions (just print it in the middle of the screen).
And also handled where only one image dimension is larger than
one screen dimension (resize the image making the larger
image dimension match the screen dimension).
Having some trouble deciding what to do if both image dimensions
are larger than both screen dimensions:
Code:
if (oldx > 320 && oldy > 568) { // image is taller and wider than the screen
if (oldx-320 < oldy-568) {
newx = oldx / oldy * 568; // get new width
newy = 568;
posx = centerx - (newx/2); // get new x position
posy = centery - (newy/2);
} else {
newy = oldy / oldx * 320; // get new height
newx = 320;
posy = centery - (newy/2); // get new y position
posx = centerx - (newx/2);
}
}
centerx and century are just coordinates for the centre of the screen,
and might as well be 160 and 284...
They are only variables because I sometimes move the image around.
Now one example actual problem is, if the input image dimensions are
640x958, the output dimensions are 379x568 (adjusted to the wrong dimension so 379 is wider than the screen),
if the input dimensions are 534x660, the output is 320x395... Correct!!
I think the solution lies in the second if/then line.
Any help appreciated!!
EDIT,,, whoops.. posx and posy are the screen coords to draw the image.
if the image is 320x568, posx and posy should both be zero because the
image dimensions match the screen size exactly.