1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| package com.colin.tool.img;
import java.awt.*; import java.util.List; import java.awt.image.BufferedImage;
public class ImageUtil {
public static ImageBuilder getComicStrip(int outWidth, int outHeight, List<BufferedImage> imageList) { int showW = outWidth, showH = outHeight; double outScale = outHeight / outWidth; final ImageBuilder imageBuilder = new ImageBuilder(showW * imageList.size(), showH, Color.BLACK); for (int i = 0; i < imageList.size(); i++) { BufferedImage image = imageList.get(i); final double height = image.getHeight(); final double width = image.getWidth(); double scale = height / width; if(scale == outScale) { imageBuilder.drawImg(image, i * showW, 0, showW, showH); } else { if(scale > outHeight) { double n = height / showH; double w = width / n; imageBuilder.drawImg(image, (int)(showW * i + (showW - w) / 2), 0, (int)w, showH); } else { double n = width / showW; double h = height / n; imageBuilder.drawImg(image, showW * i, (int)((showH - h) / 2), showW, (int)h); } } } return imageBuilder; } }
|