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?
Update:
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.