How to calculate new height and width for an image to fit with in predefined height and width, without affecting the image real aspect ratio in java?
I want to scale images to fit with in some predefined size without affecting the actual image's aspect ratio.
Do we have any predefined algorithms for that in java?
U开发者_运维知识库pdate:
Resizing Like this. The output is the same image but in smaller size. The outside frame is just a mark.
you're going to have gaps in either the width or the height... the question is figuring out which.
double widthRatio = realWidth / definedWidth;
double heightRatio = realHeight / definedHeight;
if(heightRatio > widthRatio) {
// scale image to match the height, and let the width have the gaps
} else {
// scale image to match the width, and let the height have the gaps
}
精彩评论