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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| package com.colin.tool.img;
import java.awt.*; import java.awt.image.BufferedImage;
public class ImageUtil {
public static ImageBuilder getComicStrip(BufferedImage[] imgArray, int outHeight) { int showW = outHeight, showH = outHeight; final ImageBuilder imageBuilder = new ImageBuilder(showW * imgArray.length, showH, Color.BLACK); for (int i = 0; i < imgArray.length; i++) { BufferedImage image = imgArray[i]; final int height = image.getHeight(); final int width = image.getWidth(); if (height == width) { imageBuilder.drawImg(image, i * showW, 0, showW, showH); } else { if(height > width) { double n = (double) height / showH; double w = width / n; imageBuilder.drawImg(image, (int)(showW * i + (showH - w) / 2), 0, (int)w, showH); } else { double n = (double) width / showW; double h = height / n; imageBuilder.drawImg(image, showW * i, (int)((showW - h) / 2), showW, (int)h); } } } return imageBuilder; }
public static ImageBuilder addComicStripIndex(BufferedImage comicStrip, float transparency, int strokeWidth) { final int width = comicStrip.getWidth(), height = comicStrip.getHeight(), offset = height; int length = width / height; final ImageBuilder imageBuilder = new ImageBuilder(width + offset, height); BufferedImage banner = ImageBuilder.cut(comicStrip, 0, 0, height, height); imageBuilder.drawImg(banner, 0, 0, height, height); imageBuilder.drawImg(comicStrip, offset, 0, width, height); for (int i = 0; i < length; i++) { double w = height - strokeWidth, base = width / w, h = height / base; final int x = height * i + offset + strokeWidth / 2, y = (int)(height - h); imageBuilder.drawTranslucentImage(comicStrip, x, y, (int)w, (int)h, transparency); if(strokeWidth > 0) { imageBuilder.setColor(Color.BLACK); imageBuilder.drawRect(x + (i * (int)h), y, (int)h, (int)h, strokeWidth); } if(transparency < 1) { BufferedImage frame = ImageBuilder.cut(comicStrip, height * i, 0, height, height); imageBuilder.drawImg(frame, x + (i * (int)h), y, (int)h, (int)h); } } return imageBuilder; } }
|